Flash AS3 play movieclip from main timeline on certain frame - actionscript-3

I can't seem to find the right script to let my movieclip play when a certain frame reaches on the main timeline. Searched a dozen websites, I'm not quite the coder but hope you guys can tell me the best way.
Thanks!

There are some different solutions for this, the most appropriate would be to not code at all on the timeline. But if you are using the timeline, then write on that specific frame:
myMC.gotoAndPlay(frameNumber);
Where myMC is the INSTANCE NAMEof the movieclip object placed on the stage (you can change it in the properties panel) and frameNumber is the number of the frame where you want to play the movieclip from.

Related

AS3 movie instance turning null

I'm banging my head on what seems like a simple as3 problem. I have a flash chart that contains a series of buttons that go to different parts of the timeline on Roll_over.
so for example - the "Market maneuvers" button looks like this
marketManeuversButton.addEventListener(MouseEvent.ROLL_OVER, marketManeuversButtonReaction)
and the function it calls looks like this
function marketManeuversButtonReaction (event:MouseEvent):void{ gotoAndStop('18'); }
The problem is, when I mouseover that button (and many others), it goes to frame '18' and then throws this error:
Error #1009 Cannot access a property or method of a null object
reference
here is my flash file
Any help would be appreciated. Thanks.
When you change frame, flash recreated all objects in frame, and you loose all your data.
Yes, it's simple AS3 problem, just don't use a scene frames at all. Program all in classes, don't use any frames to code any logic except stop(), gotoAndStop(), gotoAndPlay().
In your problem, put all scene in movieclip, exclude control buttons from it to another movieclip and control scene movie clip with control movieclip >____<. It pegleg. Next time just do it right, don't use scene frames.

Flash Actionscript 3.0 MovieClip Transitions (No Buttons)

I have 3 mc_MovieClips.
Each clip is on a different frame of the same layer in the main scene.
I do not want to use a button to control the play.
On startup, I want Clip1(On Frame1) to play, and when that is finished, Clip2(On Frame2) will play and so on.
I am a very beginner and using Flash Professional CC and actionscript 3.0. The only help I can seem to find calls for global variables, which no longer seem to exist.
I can provide more information if needed, I am just a really big beginner.
Try placing a parent.nextFrame(); on the last frame of each MovieClip and a stop(); on each frame of the parent clip (actual frames of your main scene).

Adobe Flash CS5.5 Actionscript 3 Buttons within movieclips cause swf preview and debugger to freeze

To say i am new to actionscript 3.0 is an understatement. But i am still trying to use it anyway. At the moment i am trying to create an interactive movie, with each frame in the main timeline containing a movieclip, and the movieclips containing the choices are the ones with buttons.
The issue here is simple, when the first button comes up the video freezes, and it seems like i can click the button but nothing happens when its clicked.
I have tried searching for a solution but it seems the only thing that comes up are ways to get the player to freeze when a button is clicked, sort of the opposite of what i'm looking for :)
The code at this point is really simple:
import flash.events.MouseEvent;
import flash.display.MovieClip;
this.Choice1R.addEventListener(MouseEvent.CLICK, ButtonHandler1);
function ButtonHandler1(e:MouseEvent){
MovieClip(this.parent as MovieClip).gotoAndPlay(3);
}
A simple stop(); tag is inside every keyframe in the main timeline to allow the movieclips inside to play, and that's about it. Every layer containing a button at this point looks sort of like this. Choice1R is in this case the instance name. If anyone can think of a reason why this would cause the swf file to freeze, any help would be appreciated.
Note: The sound keeps on playing as normal. No idea why.

stop object timeline from looping

I have a movie with several movieClips. One of the movieClips has a timeline with a motion tween. I created an instance of this movieClip:
var board:Board = new Board();
and used board.gotoAndStop(1); to keep the movieClip from playing at the beginning of the movie.
An eventListener checks to see when board collides with something; when it does, a function is invoked that uses board.gotoAndPlay(2) to get the board's timeline going.
I want the playhead on that timeline to stop at the end of the action, rather than looping. I tried to put a stop() on the last frame of that timeline, but Flash tells me I can't put an action on an object.
Can you help me solve this?
Thank you very, very much!
If memory serves, you need to make sure you have clicked in the frame in the timeline, so the frame is selected, and not an object on the stage. Then enter your actionscript.
Make sure you select a single frame where you would like to add actions then add your code
stop();
To make the timeline stop looping

AS3.0 Replay the whole movie (*SWF file)

I made a small game in Actionscript 3.0 and flash.
When the player wins the game or is 'game over' the player should have a option to replay the game.
So my question is: Is there a way to replay the whole movie with Actionscript? I know, i could reset the timeline back to 0, and re-instantiate all the classes, movieclips, var's ect... but i was wondering if anyone knows a easier solution.
Simply do this:
import flash.net.*;
//...
navigateToURL(new URLRequest(stage.loaderInfo.url), "_level0");
You can remove the swfObject and add it again. Look here. This is the swfObject reference.
Reload the page, where you've embedded the swf into, may be the easiest way.
The programmers way would be to encapsulate your whole application into a single class (extending Sprite or MovieClip) which will be attached to the stage. For restarting the game you could simply remove that instance from the stage and add a newly created onto the stage.
Or make a loader swf, that loads your game. Then if the game should be restarted, discard (unload) the instance and load it again.
Its hard to tell you what you can do, if we don't know, how your project is structured.