Question

I have a SWF application (A) that has a green object which moves on both X and Y axis, this SWF application only runs with its SWF loader (B).

I created another SWF loader (C) which loads SWF loader (B). I want to know if it is possible to get the instance of that green object and its properties.

Or making a function to search for that green color on the stage and return X, Y position using the getPixels() method?

Was it helpful?

Solution

No, you shouldn't use getPixels it will be overkill for such task. Actually Loader has content property:

Contains the root display object of the SWF file or image (JPG, PNG, or GIF) file that was loaded by using the load() or loadBytes() methods.

You will be able to get desired green object by simply operating over display list, and understanding what are you doing after component is loaded. If you add content to the display list after every loading operation (Ex: addChild(loader.content)); and for example your green object has name (Ex: 'greenLantern') after full loading you will be able to get reference on it:

//After full loading, Code in loader C
var containerB: DisplayObjectContainer = getChildAt(0) as DisplayObjectContainer;
var appA: DisplayObjectContainer = containerB.getChildAt(0) as DisplayObjectContainer;
var greenLantern: DisplayObject = appA.getChildByName("greenLantern");

trace(greenLantern.magicProperty1, greenLantern.x, greenLantern.y);

Another approach is event bubbling. You could spawn event from application A and listen for it in loader C:

//Loader C
addEventListener("greenLanternHere", onGreenLanternEvent);
function onGreenLanternEvent(e:Event):void {
    //Heeeellooooo moving green object
    trace(e.target);
}

//Application A
greenLanternInstance.dispatchEvent(new Event("greenLanternHere", true));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top