pass var values from one swf to another swf who is loaded inside the firts one in AS3

五迷三道 提交于 2019-12-20 04:38:29

问题


im using this method to load an SWF inside another SWF: (this code is inside main.swf)

function loadImage(url:String):void {
imageLoader = new Loader();
imageLoader.load(new URLRequest(url));
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
loadImage("test1.swf");

function imageLoaded(e:Event):void {
MyMovieClip.addChild(imageLoader); 
} 

The think is the test1.swf needs a value who is in the loader swf (main.swf), how can i pass the value? Thanks!


回答1:


You could create a class for the loaded SWF ( test1.swf ) which you can assign with the Document class.

In this class create a setter for the values you need to pass to the loaded SWF.

   //Here the choice of Array is arbitrary & depends on what values
   //you need to pass to the SWF...
   private var _params:Array;
   public function set params( value:Array ):void
   {
      _params = value;
   }

Then in your Main class, you can do the following:

  //Assuming you'd like to pass a number of values...
  function imageLoaded(e:Event):void {

      var content:MovieClip = imageLoader.content as CustomClass;
      content.params = [ value1 , value2... valueN];
      MyMovieClip.addChild(content);
  } 



回答2:


You need to access the content of the loader to do this. In your imageLoaded function do this.

( e.target.content as Object ).someParam = "whatever";

There are a number of security restrictions to consider, (This is called cross scripting), but if you are loading two swfs from the same domain, you shouldn't have a problem.



来源:https://stackoverflow.com/questions/4576719/pass-var-values-from-one-swf-to-another-swf-who-is-loaded-inside-the-firts-one-i

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