Can I pass parameters from and external .swf using Actionscript 3.0?

不问归期 提交于 2020-01-25 20:51:21

问题


I have a main .fla file that I am using to load a sequence of three games. If the user wins a game, they go on to the next game. Is it in any way possible to pass to the main project whether the user has won the game? I have tried using loader.content, but that does not seem to be working. I am using Flash CS3.


回答1:


You can pass data to and from loaded swfs no problem. What it sounds like you are trying to do is communicate from the loaded swf to the loading swf. The ideal way to do this is to dispatch an event on the loaded swf and listen for it in the loading swf. Roughly (not tested it because i'm in a rush) you need something like this. Load the swf. Have a load complete handler. Get the content of the loader and listen to a custom event. You can pass whatever you want on this custom event.

var myLoader:Loader = new Loader(); 
var url:URLRequest = new URLRequest("myExternalMovie.swf"); 
myLoader.load(url);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event : Event)
{
    var contenet : MovieClip = event.target.content;
    content.addEventListener(yourGameEvent.GAME_COMPLETE, yourGameEventHandler);

}

If you've never used custom events before check this link (or google for more)

http://www.adobe.com/devnet/flash/articles/creating_events.html

As a disclaimer thats the quick way to get the data into you main class. Personally i'm not a massive fan of passing data in events. I'd rather fire a empty event and the get data from properties of the firing object)... but that's just a personal preference.




回答2:


You can use the LocalConnection class.



来源:https://stackoverflow.com/questions/763575/can-i-pass-parameters-from-and-external-swf-using-actionscript-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!