To animate an object in Macromedia Flash using ActionScript 2.0, the object should be a movie clip rather than a button, as buttons are stationary by default. An invisible button can be created to trigger the animation by changing the frame of the movie clip, which contains the movement code. The recommended approach involves using an enterFrame event to check the object's position relative to a target location, allowing for smooth tweening. For multiple target positions, it's more efficient to use a single frame with conditional statements to update the target location rather than creating multiple frames for each tween. This method simplifies the code and enhances performance by minimizing unnecessary computations.
#1
brandy
156
0
I need code to "tween" an object in macromedia flash (actionscript V2.0)
The code is for a button but the button is not the object to be animated.
the object is separate. and the button stays in position.
help?
Right, you cannot tween buttons, they are by default stationary and quite unexciting. In fact (at least back in the day), buttons were really only used to monitor mouse interaction. Basically, since you can do much "cooler" stuff with a movie clip than a button, the buttons would actually be movie clips.
The idea is then you create a button, and set the alpha to 0%. Then, you can say when the invisible button which is on top and the same size as the movie clip is clicked, you tell the movie clip to go to a certain frame, which does something.
So, in my example, you have an object that you want to move. It has two frames, both with stops on the frame actions. So, at first, it is on the first frame and does nothing.
Then, when the button is clicked, you tell the movie clip to go to the next frame. On 'that' frame, you have your code that tells it to move per the code I gave a little bit ago.
Now, what you can also do is tell it to stop moving. So, if you have a lot of moving objects running around, you don't want the ones that aren't moving much to actually be running code (it can slow down the movie/animation). So, you can modify the above cod eto something like:
So, when the object gets to where you want it, you tell it to go to the next frame, where you have anothe stop, which stops the enterFrame actions from computing.
#5
brandy
156
0
can you give me code for the one frame. because having multiple frames is what i kinda wanted to avoid.
I can, but with a single frame, the object needs to constantly check to see if a condition has been met. You can do this with a simple IF construct. So, let's give the movie clip that is to be moved an instance name of moving_mc. We could have this code on the invisible button:
Code:
onMouseRelease(){
moving_mc.test = 1
}
Wait, no that won't work. You'll need to declare a frame variable, not on the object. Because the object's variable will update it every frame, so if you initialize it to a value, then try to overwrite it based on a button mouse action, then it will "reset" the next frame.
To be honest, the easiest way is two frames. Much cleaner and will run faster/better too.
#7
brandy
156
0
its just that i want the viewer to click on the next button and then the object be tweened right into position and when the viewer clicks previous button the object is tween left.
using the two frames method its sounds like it could get complicated.
On each click you can then simply change the target location for the tween. So, put the target locations on an empty movie clip and use the button to cycle between them. You can either use two frames on the empty movie clip, or use IF statements. So, for instance, name your movie clip instance targetlocs. Then, your code will be slightly modified to:
5 frames. Use whatever method you're most comfortable with. However, just realize that you do not want manual tweens. If you try to do this manually, then you'll need a specific tween for each motion; or 5! permutations = 120 different tweening actions.
By simply using code that changes a target, you can let the moving movie clip go where it wants by simply changing the place that it's trying to get to.