views:

218

answers:

1

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 ?

A: 

Found a solution some days after the post :)

After the swf is loaded you can use the following code to access the internal functions (in this example initApp()):

public function getInnerSWF():Object
{
  var sysMan:SystemManager = swfLoader.content as SystemManager;<br>
        return sysMan.document;
}

getInnerSWF().initApp();
Trantec