nix
nix

Reputation: 2285

Accessing variables of of loaded swf

I'm loading swf externally. I need to access it's methods and variables. This is the code I'm using:

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.MovieClip;

var loader:Loader;
var req:URLRequest = new URLRequest("aaa.swf");
var mc:MovieClip;

createLoader();

function createLoader():void    {
    loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.INIT, onSWFLoad);
    loader.load(req);
}

function onSWFLoad(e:Event):void    {
    mc = MovieClip(loader.content);
    addChild(mc);
    trace(loader.content)
}

EM is loaded SWF's document class. If questioned if variable gameEnded is declared publicly, the answer is yes. The game loads, but there is an error when calling the variable :

ReferenceError: Error #1069: Property gameEnded not found on EM__Preloader__ and there is no default value.
    at main_fla::MainTimeline/onSWFLoad()

Upvotes: 0

Views: 318

Answers (2)

nix
nix

Reputation: 2285

It turned out that I had to embed all the code in SWF (I was using some TLF in it)

Upvotes: 0

weltraumpirat
weltraumpirat

Reputation: 22604

Check your preloader setting in the ActionScript settings panel of your game.fla - EM__Preloader__ looks to me like an auto-generated class (and not your main EM class).

Also, your EM class should implement a simple interface that you can cast your loader.content to (instead of MovieClip). This way, you can be sure that the methods you need are available, and your code is type-safe. Embed this interface into your preloader.fla instead of the EM class to prevent unnecessary bloating of your SWFs.

Upvotes: 2

Related Questions