How to call a function that is declared into the main SWF from a loaded .as script?
i have two functions declared on the timeline of my .fla; xmlLoader1 and randomNumber.
Now, i need to execute this command: xmlLoader1.load(new URLRequest("http://67.23.233.236/~champate/d开发者_如何转开发jsoftlayer/reporte/estado.php?playa=489&nocache="+randomNumber()));
from a .as script loaded, but as logic, the compiler gave me an error because those function do not exist on the .as.
So, how can i modify the command in order to tell the .as script who need to search for those functions on the .fla ??? Thanks!
In one of the classes in the SWF file that is loading the second SWF you can have something like this:
private var loader:Loader;
private var secondSWF:DisplayObject;
private function loadSecondSWF():void
{
loader = new Loader();
// You should also handle error events...
loader.loaderInfo.addEventListener(Event.COMPLETE, loader_completeHandler);
loader.load(new URLRequest('path/to/second/file.swf');
}
private function loader_completeHandler(event:Event):void
{
secondSWF = loader.content;
if (secondSWF.hasOwnProperty('xmlLoader1')
{
var xmlLoader:Loader = secondSWF[xmlLoader1];
// Call the methods you need on xmlLoader if it is not null
}
}
In order for this to work with no extra steps, both SWF files have to come from the same domain.
If they reside in different domains then you need to add a crossdomain.xml
file to the root of the domain where the second SWF file is located, authorising access from the domain where the first SWF file is located. You also have to call flash.system.Security.allowDomain('domain.where.first.swf.is.located');
from the second SWF. Without these extra steps you will get security sandbox violation faults.
Well, if you declared xmlLoader1 as a function, it's not going to work! It should be a varaible of the correct loader type (URLLoader / Loader [for SWF or image (JPG, PNG, or GIF)]).
and your randomNumber function should return a String (and not a number).
Hope this helps.
精彩评论