|
-
What's wrong with this code?
I used this code on one project and it's working just fine. Then I'm using it on another project (very slightly modified) and it's giving me syntax errors:
stop();
import flash.events.KeyboardEvent;
import flash.display.MovieClip;
stage.addEventListener(KeyboardEvent.KEY_UP, MoveOn);
function MoveOn(event:KeyboardEvent):void
{
gotoAndPlay("horse"); //also tried NextFrame(); here, but didn't work either
}
//also tried it with and without code MoveOn(); at the end
-
What is the exact error you are getting?
-
It was giving me syntax errors on a bunch of the lines. However, I just opened up a whole new file and transferred everything and it worked. I'm thinking I was working in AS 2.0 by accident. Duh.
If I may ... here's what's not working now (I have one movie clip on each frame that each have this code on the last keyframe):
stop();
MovieClip(parent).canPlay = true;:
and then this code on the second frame of the maintimeline (the first frame has the code I posted before) - and, yet, it moves me on to the next frame if I press a key before the movieclip has ended. Any ideas why? Should it be if(canPlay = true)
stop();
import flash.events.KeyboardEvent;
import flash.display.MovieClip;
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
var canPlay:Boolean = false;
function keyHandler(e:KeyboardEvent):void
{
if(canPlay)
{
nextFrame();
canPlay = false;
}
}
-
If I read you right, you have at least 3 frames with the following code in them:
Code:
stop();
import flash.events.KeyboardEvent;
import flash.display.MovieClip;
stage.addEventListener(KeyboardEvent.KEY_UP, MoveOn);
function MoveOn(event:KeyboardEvent):void{
gotoAndPlay("horse");
}
Code:
stop();
import flash.events.KeyboardEvent;
import flash.display.MovieClip;
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
var canPlay:Boolean = false;
function keyHandler(e:KeyboardEvent):void{
if(canPlay){
nextFrame();
canPlay = false;
}
}
Code:
stop();
MovieClip(parent).canPlay = true;:
The event handler you added to the stage in the first frame was never removed, so it's still active and sends you to "horse" when it gets a key_up.
-
Ahh, event listener.
Well, I changed it to this on frame 1:
stop();
import flash.events.KeyboardEvent;
import flash.display.MovieClip;
stage.addEventListener(KeyboardEvent.KEY_UP, MoveOn);
function MoveOn(event:KeyboardEvent):void
{
stage.removeEventListener(KeyboardEvent.KEY_UP, MoveOn);
nextFrame();
}
and this on frame 2:
stop();
import flash.events.KeyboardEvent;
import flash.display.MovieClip;
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
var donePlay:Boolean = false;
function keyHandler(event:KeyboardEvent):void
{
if(donePlay);
{
stage.removeEventListener(KeyboardEvent.KEY_UP, MoveOn);
nextFrame();
donePlay = false;
}
}
and it still lets me go from Frame 2 to Frame 3 even when the movieclip is not done playing (meaning mc gets cut off). Seems like donePlay = true; is not happening for some reason.
Last edited by Leftyplayer; 08-13-2009 at 01:34 PM.
-
Fixed! (and it's embarrassing how simple the problem was)
Code needed to be: if(donePlay == true) (without the semicolon
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|