Does setting properties in AS3 prevent timeline tweens? - actionscript-3

If I have a movieclip that has a class assigned to it and I change a property of that movieclip in code, it seems that the property can no longer be tweened on the timeline.
For example, if my class sets this.x = 100, and later on the timeline I tween the position of the object, that timeline tween will not occur.
Changing either scaleX or scaleY property also seems to stop timeline tweens from happening.
Has anyone else experienced this, and if so, is there a way around it?

You have it right. Changing certain properties of an MC on the stage will cause Flash to assume that you are going to position it with script, and tweens will no longer work. A couple of workarounds:
Reparent things so that you separate scripted and IDE positioning. That is, if you were tweening an object's X position and also rotating it with script, change it so that you tween the X of a container clip, and rotate an inner clip inside.
Do all your positioning with script - i.e. use the Tween class, or a tween library.
If the playhead goes past a frame where the clip is not on the stage, and then to a frame where it is, this will "reset" the clip to work with IDE positioning and tweens. This is true even if you jump past the empty frame with gotoAndPlay. So for example, if you use script to move the clip on frame 10, and then on frame 20 you do gotoAndPlay(30);, then a tween at frame 30 will work correctly if you put a blank frame somewhere between frames 20 and 30.

I would stick strictly to the as3 code if I were you.
import these at the top of your actionscript
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
and then set your tween like this:
var myTween:Tween = new Tween(object, "property", EasingType, begin, end, duration, useSeconds);

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.

MovieClip sticks to all frames

I have a MovieClip with 5 frames. On it are some other movieclips, quite a few of them. On every frame of the first MovieClip they are positoned differently and when I change the frame they change location. Everything works great until I change something within the actionscript.
If I try to color the child MovieClip or do anything with it and then change the frame, the MC stays on the same spot, it does not change location like it should (and does if I dont change it).
Why is this happening? Can I do something to fix it?
Thank you :)
Try changing the position of the movieclips dynamically, using actionscript on each frame, instead of directly on the stage.
[movieclip].x = [Number];
[movieclip].y = [Number];
I'm pretty sure objects that have been referenced in actionscript tend to ignore the IDE positioning in later frames, so you need to dynamically move them. I've seen it happen to me heaps of times.

how to move mouse slightly in AS3?

how do you write a code in AS3 that moves my mouse slightly(very slightly that can not even notice it had moved) automatically in every 5 seconds?
You can't really do that with the original OS mouse. What you can try is to hide the mouse and create your own pointer.
// import that library
import flash.ui.Mouse;
// then somewhere in your code
Mouse.hide();
Once the mouse is hidden you may add a MovieClip which contains a graphic similar to the original pointer. After that use the Tween class to move the graphic smoothly.

AS3: restoring timeline animation after code alteration

I have a movie clip that I animate in my timeline.
At a certain point of my code I need to move that mc by actionscript and at another point I need it to do the timeline animation.
Now, I know that if I alter my movieclip through AS the timeline animations will be ignored further on, but I was wondering: is there a way to force the movieclip to follow the timeline tweenings back again?
No. Once you change a property, it is detached from the timeline.
One solution is having another movieclip inside that movieclip. That way, the timeline animates the main movieclip, but you can access the inner movieclip with a reference to it and do whatever additional transformations you want to it. How you do this will depend on what exactly you're doing, and you have to remember the transformations will "stack", but it works.

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);
}
}