Stop(); in nested movie clip doesn't work AS3 - actionscript-3

I have a movie clip on my timeline, which I then move on main timeline using classic tween from one side to another. I do not want that mc to loop so once the animation inside it finishes it should stop and all frames should be visible until the tween on main timeline finishes. To stop it from looping I added new keframe with stop(); at the end inside the movie clip. But it doesn't work, the movie clip keeps looping. I have changed the property type on first frame in the main timeline from movieclip to Graphic so that I can preview the movie clip in the timeline. In previous versions of Flash it worked always fine, but in CC the stop(); is ignored.
I know AS won't work with Graphics, but as far as the AS is inside that Graphic that shouldn't matter. Could anyone explain it to me and provide some solution please?

Your animation is happening on the root timeline so you need to put your stop(); on the last keyframe on your main time line. Or create the animation inside your movieclip and put the stop(); on the last keyframe in there instead and put the movieclip on the stage.

Try this code it works 100%
Paste the below code your main time line and called MovieClip_name.stopAllClips();
MovieClip.prototype.stopAllClips = function():void {
var mc:MovieClip = this;
var n:int = mc.numChildren;
mc.stop();
for (var i:int=0; i<n; i++) {
var clip:MovieClip = mc.getChildAt(i) as MovieClip;
if (clip) {
clip.stop();
clip.stopAllClips();
}
} }

Related

How to play animation and then play reverse on hover, start playing again until end on hover out using in Adobe Animate (Flash)?

Sorry this is so specific but I have combed through so many pages and videos and tutorials and can't figure this out.
I have all of my animations within a MovieClip. In the movie clip is also a stage sized white square button with the instance name "btn". Back on the main stage I have a second layer called "actions" with the following code applied to the first (and only) frame. It's not working. At all. (HUGE) tia
stop(); // this will stop the movie from playing at the start
btn.addEventListener((MouseEvent.ROLL_OVER, playMovie);
btn.addEventListener((MouseEvent.ROLL_OUT, stopMovie);
function playMovie(evt:MouseEvent):void {
play();
}
function stopMovie(evt:MouseEvent):void {
stop();
}
The problem is when you say play(); or stop(); which object are you really commanding? Your playMovie function could be in theory used to control many MovieClips at once, in different ways, so be specific with your commands...
btn.play(); //start the playback of "btn" MC
btn.stop(); //stop the playback of "btn" MC
Also consider using MOUSE_OVER/OUT instead ROLL_OVER/OUT etc but whatever works for you.
For reversing you will use btn.prevFrame(); together with an ENTER_FRAME event function. This function reads your Document settings for the FPS. For example, if you set 30 frames-per-sec then whatever instructions you put inside the event function will be processed 30 times per second.
See this other Answer for advice about reversing the playback of a MovieClip.
#VC.One is correct in how you should implement a solve to your issue, however in response to your comment on their answer, I thought I would demonstrate how to implement this fully for you - incase they don't.
var removeUpdate = false;
btn.addEventListener(MouseEvent.MOUSE_OVER, playMovie);
btn.addEventListener(MouseEvent.MOUSE_OUT, stopMovie);
function playMovie(evt:MouseEvent):void {
// Stop rewinding the movie clip and play it
if(removeUpdate){
stage.removeEventListener(Event.ENTER_FRAME, update);
removeUpdate = false;
}
// play our button
btn.play();
}
function stopMovie(evt:MouseEvent):void {
// stop our button
btn.stop();
// ... and rewind it
stage.addEventListener(Event.ENTER_FRAME, update);
removeUpdate = true;
}
function update(evt: Event){
// moves the button movie clip backwards one frame.
btn.prevFrame();
// If we have finished rewinding the movie clip, then stop
if(btn.currentFrame == 1){
stage.removeEventListener(Event.ENTER_FRAME, update);
removeUpdate = false;
}
}
It is important that you remove the update event because if you don't, the movie will never play again, because it will go one frame forward and then back again every frame due to; btn.play(); btn.prevFrame();

ColorTransform for multiple movie clips

Despite searching both the web and youtube for a solution, it remains difficult to find information on colorTransforming multiple movie clips in AS3. I found a video on youtube about colorTransform which i followed steps to create a fully functional colorTransform for a single clip but i would like to use it for multiple clips and be able to change colors for each on a mouse click.
I have included the code below and perhaps someone knows how i can add more movie clips to it. When i copy and change mc1. EventListener code to mc2, i get a duplicate function error which i don't know how to fix.
import flash.geom.ColorTransform;
import flash.geom.ColorTransform;
import flash.events.MouseEvent;
// this here is the little movieclip where the main clip gets its color from,the clip is made up of two movieclips but can also be one movieclip
// instead of brushColor i have used myColor and instead of brush.tip i have used square.
var myColor:ColorTransform=new ColorTransform();
myColor.color=0xffffff; square.transform.colorTransform=myColor
red.addEventListener(MouseEvent.CLICK,onclick);
green.addEventListener(MouseEvent.CLICK,onclick);
blue.addEventListener(MouseEvent.CLICK,onclick);
orange.addEventListener(MouseEvent.CLICK,onclick);
yellow.addEventListener(MouseEvent.CLICK,onclick);
pink.addEventListener(MouseEvent.CLICK,onclick);
function onclick(event:MouseEvent){
if(event.target==red)
{myColor.color=0xff0000}
else if(event.target==green)
{myColor.color=0x99ff33}
else if(event.target==blue)
{myColor.color=0x00ccff}
else if(event.target==orange)
{myColor.color=0xffcc33}
enter code here
else if(event.target==yellow)
{myColor.color=0xffff66}
else if(event.target==pink)
{myColor.color=0xff99ff}
else
{myColor.color=0x666666}
square.transform.colorTransform=myColor
}
mc1.addEventListener(MouseEvent.CLICK, colorChange);
function colorChange(event:MouseEvent)
{
mc1.transform.colorTransform=myColor;
}
// upto here the code works fine but from below i get a duplicate fuction error which i don't know how to fix.
// the idea is to add more movie clips so i can change their colors just like i can do for mc1.
1021: DUPLICATE FUNCTION DEFINITION "ERROR"
mc2.addEventListener(MouseEvent.CLICK, colorChange);
function colorChange(event:MouseEvent)
{
mc2.transform.colorTransform=myColor;
}
Push all movieclips into array and then add eventlistener to all of them like this:
var mcArray:Array=new Array();
mcArray.push(mc1,mc2);
for (var i:int=0;i<mcArray.length;i++)
{
mcArray[i].addEventListener(MouseEvent.CLICK,colorChange);
}
And add only one colorChange function like this:
function colorChange(event:MouseEvent)
{
e.currentTarget.transform.colorTransform=myColor;
}

Clicking on a movieclip inside another movieclip on AS3

Alright, what i need it's simple but its driving me crazy, i want to know if AS3 detects my mouse inside a movieclip.
For example, i have a movieclip instanced "BEframes" which is inside movieclip "BE1" and i want to put him inside a new movieclip instanced "roll". So the order would be roll > BE1 > BEframes.
I want to know if flash will only detect "roll" or he will detect all movieclips, thank you,
for(i=1;i<=77;i++){
var str:String =("BE" + i);
this[str].BEframes.gotoAndStop(i);
this[str].addEventListener(MouseEvent.CLICK, clique);
this[str].addEventListener(MouseEvent.ROLL_OVER, over);
this[str].addEventListener(MouseEvent.ROLL_OUT, out);
}
function clique(evt:MouseEvent):void{
var botao:String = evt.currentTarget.name.toString();
var num:String = botao.replace("BE", "");
parede_esquerda.gotoAndStop(num);
}
function out(evt:MouseEvent):void {
evt.currentTarget.gotoAndPlay("out");
}`enter code here`
function over(evt:MouseEvent):void {
evt.currentTarget.gotoAndPlay("over");
}
*
Probably, you should use MOUSE_OVER and MOUSE_OUT instead of ROLL_OVER and ROLL_OUT.
this[str].addEventListener(MouseEvent.MOUSE_OVER, over);
this[str].addEventListener(MouseEvent.MOUSE_OUT, out);
To avoid receiving mouseEvent for movieClips set mouseEnabled to false, i.e if you don't want clip roll's mouse event setroll.mouseEnabled = false so that the object below will receive mouseEvent

How to make a symbol remove itself at a certain frame?

I'm struggling on doing a simple thing, I have an object that generates a smoke trail by creating and adding a simple animation done in flash. All works fine but I can't seem to find an easy way to make the smoke remove itself after playing the animation, if i add something like this.parent.removeChild(this); to the last frame of the animation the app simply crashes with Cannot access a property or method of a null object reference.
what am i doing wrong?
the animation keeps playing even thought the object is no longer being rendered, at the second call of this.parent.removeChild(this); the object was no longer parented to any object, stopping the animation solved the problem
thank you frankhermes
this.parent.removeChild(this);
this.stop();
in your main Movie clip assigned below code to a button(show button):
var swfLoader:Loader = new Loader();
stage.addChild(swfLoader);
var swfURL:URLRequest = new URLRequest("yourchildSWF.swf");
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
swfLoader.load(swfURL);
function loadComplete(e:Event):void
{
//swfLoader.x = (stage.stageWidth-swfLoader.width)/2; //for center align
//swfLoader.y = (stage.stageHeight-swfLoader.height)/2; //for center align
swfLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
swfLoader.content.addEventListener(MouseEvent.CLICK, function(e:Event)
{
swfLoader.unload();
} );
}
you must have a button in your child swf. when pressed on it, swf will be closed.(create a symbole as button for close button)
does not need any code in child swf.

Adding stop(); to a movieclip on the timeline is causing the tweens in said movieclip to not play, the movieclip just skips to the end

I've got a movieclip that is composed of 3 separate symbols. 2 of the symbols have their alpha tweened over 60 frames. 1 of the symbols is not tweened at all. All symbols are in separate layers, and there is a 4th, empty layer with a keyframe on frame 60 for actionscript.
The actionscript on frame 60 is simply "stop();" .
I am adding an instance of the movieclip to the stage dynamically from the document class. When I have "stop();" in there, the movieclip appears on the stage and skips straight to frame 60, where it succesfully stops.
Without "stop();" in there, the movieclip plays the alpha tweens perfectly, but obviously continuously loops.
Manually dispatching an Event.COMPLETE and listening for it does not work either and I would prefer not doing it that way anyway.
Here is the code that adds the movieclip to the stage:
//initialize the gameplay, remove title screen.
private function initialize_gameplay():void
{
//remove the title screen
initialize_title_screen(true);
this.screen_transition_obj = new tide_out_video();
this.addChild(this.screen_transition_obj);
this.game_board = new tidepool_gameboard();
this.screen_transition_obj.addEventListener(Event.COMPLETE,swap_transition_video_for_screen);
}
//replace the current transition video with the screen it was transitioning to
private function swap_transition_video_for_screen(e:Event){
this.addChild(this.game_board);
if(this.screen_transition_obj != null){
if(this.getChildByName(this.screen_transition_obj.name)){
this.removeChild(this.screen_transition_obj);
}
this.screen_transition_obj.removeEventListener(Event.COMPLETE, swap_transition_video_for_screen);
this.screen_transition_obj = null;
}
}
The movieclip's class is tidepool_gameboard and the property of the document class that stores the reference to it is game_board.
Any idea why putting stop(); on frame 60 of the movie clip is causing it to skip to the end without tweening?
UPDATE:
Adding the movieclip to the stage instantly instead of as the result of an event listener works properly, the problem only occurs when the movieclip is added in the event listner.
I can't believe I overlooked this, as it appears to be fairly obvious to me now.
In the code posted in the question, I've initialized a new instance of this.game_board, then added it to the stage after a delay based on an event listener for a video clip. The animation is playing, but it's playing before the clip ever is added to the stage.
Thanks go to alecmce who answered this question.
I did his Event.ADDED_TO_STAGE event listener, and it worked, which led me to realize that the MovieClip does not wait until it is added to the stage to start playing its own timeline, it simply starts the second you instantiate the object.
This is the new, fully functional code:
//initialize the gameplay, remove title screen.
private function initialize_gameplay():void
{
//remove the title screen
initialize_title_screen(true);
this.screen_transition_obj = new tide_out_video();
this.addChild(this.screen_transition_obj);
this.screen_transition_obj.addEventListener(Event.COMPLETE,swap_transition_video_for_screen);
}
//replace the current transition video with the screen it was transitioning to
private function swap_transition_video_for_screen(e:Event)
{
this.game_board = new tidepool_gameboard();
this.addChild(this.game_board);
if (this.screen_transition_obj != null)
{
if (this.getChildByName(this.screen_transition_obj.name))
{
this.removeChild(this.screen_transition_obj);
}
this.screen_transition_obj.removeEventListener(Event.COMPLETE, swap_transition_video_for_screen);
this.screen_transition_obj = null;
}
}