Actionscript 2.0 flash - actionscript-3

I have written this basic button code a thousand times before on CS5. Now I bought CS6 and this simple AS2 code is not working.
On the first frame I made a movieClip symbol and added in its actions :
on(release){
gotoAndPlay(2);
}
Then I made a new layer on top, I typed :
stop();
in the frame's action.
Problem: From the second frame the animation was supposed to start, but it didn't work and stayed on the first frame even when I clicked the button several times. How to fix this issue?
I have even tried :
rooting on(release)
{ _.root.gotoAndPlay(2); }

Related

How to make a movieclip play on a specific frame in AS3?

I'm incredibly rusty at Flash having not touched it in probably 10 years and can't seem to figure this out, or find it online:
I have a MovieClip with two layers, each having a Shape Tween. Basically its a Door that opens and closes.
I dropped it onto the main timeline but now I need it to start and stop. This is where I'm now struggling since the last time I used Flash actions could go on specific keyframes.
I made a new layer called actions just to keep things organized and currently have:
barrier1.stop();
I just want something that lets me state a frame, say 57 to have barrier1 start playing on. Tried using play(); and Event.ENTER_FRAME with no luck. How would I set this up?
Well it is easy with the instance name of your movieClip
barrier1.stop(); // Stops the movieClip
barrier1.play(); // Resumes
barrier1.gotoAndStop(12) // Goes to 12nd frame and stop
barrier1.gotoAndPlay(12) // Goes to 12nd frame and play
barrier1.currentFrame // returns barrier currentframe
For capturing frame from scene level:
this.addEventListener(Event.ENTER_FRAME,onLoop);
function onLoop(event:Event){
if(barrier1.currentFrame == 57){
trace("BARRIER is in 57. frame");
}
}
Inside on the animation clip on the first frame
var root:MovieClip = this.parent as MovieClip
root.makeStartSceneAnimation()
**in timeline scene level [root]**
function makeStartSceneAnimation(){
/// barrier started to play
}
If you are using timeline, you can add Key frame on the desired frame, and then add stop(); as Action in the action layer. But bear in mind that if you do this in the main timeline - it will stop everything. If you want to stop that MovieClip, then you have to do this inside MoviceClip's timeline.

Movie Clips frozen but swf has not crashed - AS3 CS6

I'm making a top down shooter for a college project. I'm getting extremely low on available time left to complete this.
I followed a tutorial as we was not taught any AS3 although expected to creating a game in this language so there is commented code due to this. The tutorial lead me up to creating a player on the stage that moves by keyboard presses and can fire bullets by pressing the left mouse button, but it didn't help with creating enemies at all.
So I created an enemy movie clip that just spawns on the stage at X=0 and Y=0 (random spawning will be added later), and it's supposed to move towards the players location but it doesn't. When the swf loads up it appears they have started to move but have frozen on the screen. It's not crashed because I can still move the player around and fire bullets? Any help is appreciated.
Main.as code
Enemy.as code
Well, you are not calling the moveTowards() in any loop -> the position is not updated. Or where exactly are you updating the enemy's position? I see only one setting of .x, .y of enemy and it is right after you create the object, no further updates.
Put this into your loop function in Main.as:
for(var i:int=0; i<enemies.length; i++) {
Enemy(enemies[i]).moveTowards(player.x, player.y);
}

Flash CS5 does not compile any timeline AS3 anymore

All the sudden Flash CS5 has stopped compiling any AS3. For example, if I create a new document and place these simple scripts on the timeline, the resulting SWF ignores the actions completely:
trace("HELLO"); // I get no "HELLO" in the output window
stop(); // on frame 2 I have a square, the SWF just loops endlessly between the two frames
alpha = .1; // the square is not fade as expected
In an AS2 document I get no trace() output, but actions DO work.
Does anyone have any ideas what's wrong? Any ideas how to fix this, other than a clean re-install?
Thanks.

Targeting Root from a Movieclip

Im having trouble targeting back to the main timeline from within a movie clip AS3.
I have tried the code below but still does nothing? I have labelled the frame in which I would like it to go to on the main time and added this code to the actions within in the movie clip, but when I click the button it does nothing? I have no errors come up?
Any ideas?
map_UK.addEventListener(MouseEvent.CLICK, MAIN);
function MAIN(e:MouseEvent):void
{
MovieClip(root).gotoAndPlay("MAIN");
}

Actionscript 3 how to gotoAndPlay without pressing buttons

So, I have movieclip named intro. When the intro runs out of frames, how do I tell it to gotoandPlay to maintimeline or upper movieclip without needing user to press any buttons? shouldnt be that hard, right? it was really super easy in actionscript 2, but in 3 I cant even seem to find help/tutorial to do this!
thanks!
Clarify what exactly you would like to play afterwards?
It could be as simple as adding a line of code to the last frame of the animation:
gotoAndPlay(3); // will goto a frame within the same move clip
Or to play a different movieclip:
MovieClip(this.parent as MovieClip).gotoAndPlay(3); //tell your parent to goto a specific frame
Or
MovieClip(this.parent as MovieClip).parentObject.gotoAndPlay(3); //tell one of your parents movieclips to start playing
EDIT:
A bit more out there method, placing this code on the parents timeline to check when the movieclip is finished:
intro.addEventListener(Event.ENTER_FRAME, checkFrame);
function checkFrame(e:Event):void{
if(intro.currentFrame==intro.totalFrames){
//do something
someMovieClip.gotoAndPlay(3);
}
}