views:

332

answers:

1

Okay, so I have a Flash CS3 (+ AS3) program which is loading another flash program (called "pacman_main.swf" in this example). I've determined this is a rather old SWF, as it is made in Flash 5 and AS1 (yippee!).

I want the parent SWF (a.k.a. the wrapper) to be able to access the variables, specifically the score, of the child SWFG (a.k.a. "pacman_main.swf"). This is so I can submit the score to a 3rd party PHP/mySQL db blah blah.

function checkScore() {
    // Get the score and submit it
}

submitScore.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
    checkScore();
}

var loader:Loader = new Loader();
loader.load(new URLRequest("pacman_main.swf")); 
addChildAt(loader, 0);

I know the variable name of the score, using the Debug > List Variables after building the wrapper. The score is a variable listed as "Variable _level0.instance5.instance6.score = 180" after getting 18 pac-dots in the game. How would I access that in my "checkScore" function?

Thanks!

+1  A: 

The latest flash players have two virtual machines packaged in them, the AVM2 for as3, and AVM1 for as2/as1. Because of this, when you load an as1/as2 swf into flash it is of the type AVM1Movie, which will be run by the AVM1. Unfortunately, the AVM2 has little access to the objects running on AVM1, in fact, "no interoperability (such as calling methods or using parameters) between the AVM1Movie object and AVM2 objects is allowed".

Do you have access to the as1 source code? If you do I suggest firing off events every time the score changes, you can listen for these events in your wrapper class and not have to worry about accessing the score variable directly.

You can read more about AVM1Movie here

SquareRootOf2