今天使用Ext.FlashComponent添加一个照像功能的flex发现不会执行initialize事件,找了半天没结果,翻了charts的源码才发现initializeComponent后有个javascript的回调方法
问题找到了,现在在自己的flex加个代码
[img]http://dl.iteye.com/upload/attachment/165095/dfbb939c-d7fa-3579-a4ac-7abb82713809.jpg[/img]
this.initializeComponent();
swfReady;
this.dispatchEventToJavaScript(swfReady);
protected function dispatchEventToJavaScript(param1:Object) : void
{
var event:* = param1;
try
{
if (ExternalInterface.available)
{
ExternalInterface.call(this.javaScriptEventHandler, this.elementID, event);
}
}
catch (error:Error)
{
if (error is SecurityError)
{
this.showFatalError("Warning: Cannot establish communication between YUI Charts and JavaScript. YUI Charts must be served from HTTP and cannot be viewed locally with file:/// protocol unless location is trusted by Flash Player.\n\nFor more information see:\nhttp://www.adobe.com/products/flashplayer/articles/localcontent/\n\n");
}
}
return;
}// end function
问题找到了,现在在自己的flex加个代码
protected function applicationComplete() : void
{
this.elementID = this.loaderInfo.parameters.elementID;
//从参数中得到JS提供给Actionscript的事件回调函数
this.javaScriptEventHandler = this.loaderInfo.parameters.eventHandler;
if (ExternalInterface.available)
{
this.dispatchEventToJavaScript({type:"swfReady"});
}
else
{
throw new IOError("Flash YUIComponent cannot communicate with JavaScript content.");
}
}// end function
[img]http://dl.iteye.com/upload/attachment/165095/dfbb939c-d7fa-3579-a4ac-7abb82713809.jpg[/img]