Running game, leaving game and continuing animation
Posted
by
Madrusec
on Stack Overflow
See other posts from Stack Overflow
or by Madrusec
Published on 2012-11-17T04:55:16Z
Indexed on
2012/11/17
4:59 UTC
Read the original article
Hit count: 192
actionscript-3
|flash-cs6
I have been trying to learn some Actionscript recently and have been trying to run an interactive story that at one point turns into an extremel simple shooter game. After the player either wins or looses, then he/she is taken to the rest of the animated story. So I have everything up to the point where the games runs (successfully) but for some reason I am unable to have flash run the rest of the frames, most of which have no code at all. This is the code for scene 1:
stop ();
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
var stoneInGame:uint;
var stoneMaker: Timer;
var container_mc: MovieClip;
var cursor:MovieClip;
var score:int;
var anxiety:int;
var anxiety_mc :MovieClip = new mcAnxiety();
//stage.addChild( anxiety_mc );
function initializeGame():void
{
stoneInGame = 10;
stoneMaker = new Timer(1000, stoneInGame);
container_mc = new MovieClip();
addChild(container_mc);
container_mc.addChild(anxiety_mc);
anxiety_mc.x = 497;
anxiety_mc.y = 360;
stoneMaker.addEventListener(TimerEvent.TIMER, createStones);
stoneMaker.start();
cursor = new Cursor();
addChild(cursor);
cursor.enabled = false;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);
score = 0;
anxiety = anxiety_mc.totalFrames;
anxiety_mc.gotoAndStop(anxiety);
}
function dragCursor(event:MouseEvent):void
{
cursor.x = this.mouseX;
cursor.y = this.mouseY;
}
function createStones(event:TimerEvent):void
{
var stone:MovieClip;
stone = new Stone();
stone.x = Math.random() * stage.stageWidth;
stone.y = Math.random() * stage.stageHeight;
container_mc.addChild(stone);
}
function increaseScore():void
{
score ++;
if(score >= stoneInGame)
{
dragCursor.stop();
createStones.stop();
stoneMaker.stop();
trace("you wind!");
}
}
function decreaseAnxiety():void
{
anxiety--;
if(anxiety <= 0)
{
stoneMaker.stop();
trace("you lose!");
}
else
{
anxiety_mc.gotoAndStop(anxiety);
}
increaseScore();
}
initializeGame();
So what I tried to do was adding gotoAndPlay() inside both the decreaseAnxiety and increaseScore functions after the trace statements and referenced a frame where I have more keyframes that continue a story. However, Flash just goes back to the beginning of the timeline and I even the functions that change and control the cursor seem to be running. This leads me to believe that I need to make sure that I tell flash o stup running certain functions before jumping to another frame. However, it seems to me that I would still have the same issue and not be able to continue in the timeline.
Is there something I am missing? How can I jump out of all this code once the game finishes and simply continue playing the rest of the frames? Any pointers would be greatly appreciated.
Thank you
© Stack Overflow or respective owner