Flex 3 (Action Script): How to access a function from a loaded swf-file ?
Posted
by Trantec
on Stack Overflow
See other posts from Stack Overflow
or by Trantec
Published on 2010-05-06T07:04:38Z
Indexed on
2010/05/06
7:08 UTC
Read the original article
Hit count: 207
Hi,
i load in ActionScript a swf file. So far no Problem, but I didn't found a way to access one of it's functions, the best thing would be if I could access the main function in the mxml part of the swf.
Here is the code of the main-mxml file that belongs to the swf that should load and access another swf:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="basket();">
<mx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private function basket(): void
{
var swfLoader: SWFLoader = new SWFLoader();
swfLoader.addEventListener( Event.COMPLETE, handleSWFLoaded );
try {
swfLoader.load( "../../data/InternalSWF.swf" );
} catch (error: Error) {
trace( "Couldn't load file !" );
}
}
private function handleSWFLoaded( event: Event ): void
{
var swfApp:* = event.target.content;
// This both ways don't work...
//if (swfApp.hasOwnProperty("initApp")) {
// var initApp:Function = (swfApp["initApp"] as Function);
// initApp();
//}
// swfApp.initApp();
}
]]>
</mx:Script>
<mx:Text id="output" width="100%" textAlign="center" />
</mx:Application>
The if-Statement "if (swfApp.hasOwnProperty("initApp")) {" is never true and the call "swfApp.initApp()" says that this function does not exist.
In the original version I added event listeners for HTTPStatusEvent.HTTP_STATUS, IOErrorEvent.IO_ERROR and SecurityErrorEvent.SECURITY_ERROR. But except for HTTP_STATUS = 0 none of them are called.
Is the whole idea of how i try to do this wrong ?
© Stack Overflow or respective owner