Flash AS3 - using 'gotoAndPlay' with stage vars inside MC
Posted: Thu Jan 17, 2013 5:15 am
Hello all,
I think people already know me as the developer of Mario is Missing - Peach Untold Tale. I've been programming in AS2.
But I'm in the process of learning AS3 to code two of three games here on LoK. Also because I've hit the AS2 limits.
The problem is that I need to have special movie clips with 'gotoAndPlay' in certain frames according to stage (or root) variables.
I know that AS3 teaches you to code in a main scene1 frame, or as a best pratice, in a separate AS file. The problem is that I need to put a given MC, say, character, in the stage, using the IDE (direct placement with an instance name). Once there, this character has 50 poses. Each pose has 10 clothing options. So, the arm can have one of 10 glove types, the body can have one of 10 t-shirts, and so on.
It will be a hell to just name everything (put instances) then acess them from the AS file or Scene1 frame. Also because the character is loading/unloading movieclips according to their state, because every pose is a new MC. So, when walking, the correct outfit need to be there.. When jumping, I need to use another mcs that's instantiated automatically by FLASH because the main character just plans another frame for that. And so on.
So, to tell every sub clip to search for the current oufit, I code like that in AS2 for every body part that will be used in all 50 poses (each one uses up to 10 body parts each):
How to make that in AS3?
Then I decided to simpify this code and create a Game class (same name as the project), and I've put:
in SCENE1 frame (first main frame), I've put:
Finally, in each part of the clothe frames (image above), I've put instead:
But I'm not able to play those inner frames. They dont find 'stage.game.DressSel'. I also tried putting 'root.game.DressSel'.
The error: Scene 1, Layer 'LEVEL', Frame 1, Line 5 1119: Access of possibly undefined property game through a reference with static type flash.display:Stage.
Am I doing something wrong?
I really need to use that logic ('alive' frames that go to other frames according to a global variable).
I noticed people use to ADDED_TO_STAGE event, but I dont know where to go.
Oh about the book, I've bought "ActionScript 3 Game Programming University, by Gary Rosenzweig, but the book rather uses an external AS-only code, with minimal to no code in any timeline.
Thank you really.
I think people already know me as the developer of Mario is Missing - Peach Untold Tale. I've been programming in AS2.
But I'm in the process of learning AS3 to code two of three games here on LoK. Also because I've hit the AS2 limits.
The problem is that I need to have special movie clips with 'gotoAndPlay' in certain frames according to stage (or root) variables.
I know that AS3 teaches you to code in a main scene1 frame, or as a best pratice, in a separate AS file. The problem is that I need to put a given MC, say, character, in the stage, using the IDE (direct placement with an instance name). Once there, this character has 50 poses. Each pose has 10 clothing options. So, the arm can have one of 10 glove types, the body can have one of 10 t-shirts, and so on.
It will be a hell to just name everything (put instances) then acess them from the AS file or Scene1 frame. Also because the character is loading/unloading movieclips according to their state, because every pose is a new MC. So, when walking, the correct outfit need to be there.. When jumping, I need to use another mcs that's instantiated automatically by FLASH because the main character just plans another frame for that. And so on.
So, to tell every sub clip to search for the current oufit, I code like that in AS2 for every body part that will be used in all 50 poses (each one uses up to 10 body parts each):
How to make that in AS3?
Then I decided to simpify this code and create a Game class (same name as the project), and I've put:
- Code: Select All Code
package
{
import flash.display.*;
import flash.text.*;
public class Game extends MovieClip
{
public function Game () //contructor
{
var DressSel:String="Outfit1";
}
}
}
in SCENE1 frame (first main frame), I've put:
- Code: Select All Code
var game:Game=new Game();
stage.addChild(Game);
Finally, in each part of the clothe frames (image above), I've put instead:
- Code: Select All Code
gotoAndPlay(stage.game.DressSel);
But I'm not able to play those inner frames. They dont find 'stage.game.DressSel'. I also tried putting 'root.game.DressSel'.
The error: Scene 1, Layer 'LEVEL', Frame 1, Line 5 1119: Access of possibly undefined property game through a reference with static type flash.display:Stage.
Am I doing something wrong?
I really need to use that logic ('alive' frames that go to other frames according to a global variable).
I noticed people use to ADDED_TO_STAGE event, but I dont know where to go.
Oh about the book, I've bought "ActionScript 3 Game Programming University, by Gary Rosenzweig, but the book rather uses an external AS-only code, with minimal to no code in any timeline.
Thank you really.