PDA

View Full Version : Help understanding display objects



ShooterMG
June 16th, 2007, 05:54 PM
I thought I had a fairly good grasp on display objects and the display list, but apparently I don't because I'm running into an issue.

For my game, I have a class called PlayerAtom. It's just a plain class that extends Sprite and has a few public variables, and that's it. Nothing fancy, other than it has a loader variable that loads external images.

Anyways back on the main timeline of my movie, I created a MovieClip called playerContainer. I think I've set the scenario well enough, so here's the code.

var playerContainer:MovieClip = new MovieClip();
addChild(playerContainer);
createAtoms();

function createAtoms():void {
var playerAtom: PlayerAtom = new PlayerAtom("blue.png");
playerAtom.name = "playerAtom";
playerContainer.addChild(playerAtom);

}





Ok so there's the code. For whatever reason, I absolutely cannot access the variables of playerContainer.playerAtom. If I do a trace(playerContainer.playerAtom), it returns "object PlayerAtom", so it *knows* it's there. But for whatever reason, it no longer has any variables defined. Can anybody please shed some insight?

pingnak
June 17th, 2007, 02:08 AM
Maybe step it through the debugger line-by-line and see where it 'misplaces' all of those properties?

Of course, if you're using AS2 (Flash 8 or earlier) and you're importing it into AS3 (Flex, Flash CS3), then nothing of the internal properties will be visible. To talk to the AS2 script, you'll need a LocalConnection to do RMI calls. Fun, eh?

ShooterMG
June 17th, 2007, 02:32 AM
Maybe step it through the debugger line-by-line and see where it 'misplaces' all of those properties?

Of course, if you're using AS2 (Flash 8 or earlier) and you're importing it into AS3 (Flex, Flash CS3), then nothing of the internal properties will be visible. To talk to the AS2 script, you'll need a LocalConnection to do RMI calls. Fun, eh?

I've tried that, and when I look into the properties of playerContainer, it says numChildren = 1, which would be correct, but it doesn't actually show the "playerAtom" sprite in the list of properties. Would this be an indicator that something is wrong?

sasxa
June 17th, 2007, 05:29 AM
where do you try to access them(properties)?


var playerContainer:MovieClip = new MovieClip();
addChild(playerContainer);
createAtoms();

function createAtoms():void {
var playerAtom: PlayerAtom = new PlayerAtom("blue.png");
playerAtom.name = "playerAtom";
playerContainer.addChild(playerAtom);
trace(playerContainer.playerAtom); // output: [object PlayerAtom]
trace(playerAtom); // output: [object PlayerAtom]
}
trace(playerContainer.playerAtom); // output: null (or some error even...)
trace(playerAtom); // output: null/error