gpt4 book ai didi

apache-flex - Flex 加载模块 READY 事件未触发,为什么?

转载 作者:行者123 更新时间:2023-12-01 02:59:04 25 4
gpt4 key购买 nike

您好,我有这个非常简单的 mxml 示例。

如果模块是远程的,例如 http://edofiles.s3.amazonaws.com/calculator.swf,则使用带有 flex sdk 3.4.0 的 flex builder

READY 事件从未被触发,我不明白为什么。

你有同样的行为吗?

原码来自http://lowpitch.com/blog/modulemanager-and-imoduleinfo-loading-flex-modules-dynamically/#comment-4396

有什么线索吗?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.modules.Module;
import mx.events.ModuleEvent;
import mx.modules.ModuleManager;
import mx.modules.IModuleInfo;

protected var _moduleInfo:IModuleInfo;

private function initApp():void {
addToLog ("Application initialised");
// create the module - note, we're not loading it yet
_moduleInfo = ModuleManager.getModule("http://edofiles.s3.amazonaws.com/calculator.swf");
// add some listeners
_moduleInfo.addEventListener(ModuleEvent.READY, onModuleReady);
_moduleInfo.addEventListener(ModuleEvent.SETUP, onModuleSetup);
_moduleInfo.addEventListener(ModuleEvent.UNLOAD, onModuleUnload);
_moduleInfo.addEventListener(ModuleEvent.PROGRESS, onModuleProgress);
}

protected function getModuleInfo () : IModuleInfo {
// return the module info
return _moduleInfo;
}

/**
* Adds output to the log
**/
protected function addToLog (msg:String) : void {
log.text += msg + "\n";
// scroll to the bottom on the next frame
callLater(scrollToBottom);

}

protected function scrollToBottom () : void {
// scroll to the bottom
log.verticalScrollPosition = log.maxVerticalScrollPosition;
}

/**
* Called when the "load" button is pressed
*
* Starts loading the module - when the module has been
* loaded, an instance of the module will be created
* and added to the tile control
*
**/
private function loadModule () : void {
addToLog ("Loading module");
// load the module
getModuleInfo().load();
}

/**
* Called when the "unload" button is pressed
*
* Removes all the instances of the module from the
* tile control, then unloads the module
*
*/
private function unloadModule () : void {
addToLog ("Unloading module");
// clear out all the the instances
// of the module from the tile
tile.removeAllChildren();
// unload the module
getModuleInfo().release();
//getModuleInfo().un
}

/**
* Handler for the ModuleEvent.PROGRESS event
**/
protected function onModuleProgress (e:ModuleEvent) : void {
addToLog ("ModuleEvent.PROGRESS received: " + e.bytesLoaded + " of " + e.bytesTotal + " loaded.");
}

/**
* Handler for the ModuleEvent.SETUP event
**/
private function onModuleSetup (e:ModuleEvent) : void {
addToLog ("ModuleEvent.SETUP received");
// cast the currentTarget
var moduleInfo:IModuleInfo = e.currentTarget as IModuleInfo;
addToLog ("Calling IModuleInfo.factory.info ()");
// grab the info and display information about it
var info:Object = moduleInfo.factory.info();
for (var each:String in info) {
addToLog (" " + each + " = " + info[each]);
}

}

/**
* Handler for the ModuleEvent.READY event
**/
private function onModuleReady (e:ModuleEvent):void {
addToLog ("ModuleEvent.READY received");
// cast the currentTarget
var moduleInfo:IModuleInfo = e.currentTarget as IModuleInfo;
// Add an instance of the module's class to the
// display list.
addToLog ("Calling IModuleInfo.factory.create ()");
tile.addChild( moduleInfo.factory.create () as Module);
addToLog ("SomeModule instance created and added to Display List");
}

/**
* Handler for the ModuleEvent.UNLOAD event
**/
public function onModuleUnload (e:ModuleEvent) : void {
addToLog ("ModuleEvent.UNLOAD received");
}

]]>
</mx:Script>

<mx:HBox width="100%" height="100%">
<mx:Tile id="tile" width="100%" height="100%" />
<mx:TextArea id="log" width="100%" height="100%"/>
</mx:HBox>


<mx:ApplicationControlBar>
<mx:Button label="Load" click="loadModule ()" />
<mx:Button label="Unload" click="unloadModule ()"/>
</mx:ApplicationControlBar>

</mx:Application>

最佳答案

我今天有这种行为。尽管它与发帖人的问题没有直接关系,但这个话题在谷歌搜索中的排名很高,所以我想帮助那些在这里绊倒的人。

我在以下博客中找到了解决方案:
http://www.joshuaostrom.com/2008/08/14/flex-modules-watch-your-scope/

问题是 ModuleLoader 在您调用 load() 时会自动进行垃圾收集。 ,所以如果你对你的引用不特别小心,你的听众可能会被摧毁。

关于apache-flex - Flex 加载模块 READY 事件未触发,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1557113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com