all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

Tween Class, onEnterFrame


Tween Class, onEnterFrame phonemymum
2/28/2006 9:30:36 PM
flash actionscript:
Hi I'm just trying to make my box grow with onEnterFrame - I can't figure out
why this bit of code will not work:

import mx.transitions.Tween;
import mx.transitions.easing.*;
box_mc.onEnterFrame = function() {
var t1:Tween = new Tween(this."_xscale",Strong.easeOut,100,540,1,true);
var t2:Tween = new Tween(this."_yscale",Strong.easeOut,100,540,1,true);
}

Do any of you king people know - this is my first experiment with the tween
class, but I don't think that's the issue, it is my lack of understanding
regarding onEnterFrame :-)

Chris
Re: Tween Class, onEnterFrame blemmo
2/28/2006 11:11:34 PM
Hi Chris,

quite right with the understanding... ;)
OnEnterFrame gets called repeatedly, even if you stopped the player on a
frame... Flash loops the playhead in this case, and enters the frame in the
movie's fps setting frequency. With the tween code in onEnterFrame, the tween
starts again every x milliseconds... creating a static picture. So you may say
that your code works, but you can't see it, because right after execution, you
start all over again.

To make it short: don't use onEnterFrame for the tween. It tweens anyway...

greetings,
blemmo

Re: Tween Class, onEnterFrame phonemymum
3/1/2006 12:00:00 AM
Cheers B!

I had a feeling that onEnterFrame was screwing the whole thing up, but what I
was looking for a way to initiate the action when the playhead hit the instance
on the timeline from actionscript which was sitting on the first frame.
OnEnterFrame seemed to fit the bill. When the timeline hits the frame
containing box_mc, perform the action! You see I've got into my head that
everything has to be structured neatly and precisely, to that end I want all my
action script on one frame etc. But it doesn't seem work like that. This works
for anyone who is interested:

import mx.transitions.Tween;
import mx.transitions.easing.*;

grow(this.box_mc);

function grow(box) {
var t1:Tween = new Tween(box,"_xscale",Strong.easeOut,100,400,1,true);
var t2:Tween = new Tween(box,"_yscale",Strong.easeOut,100,400,1,true);
}
stop();

But this code has to sit 'with' the box_mc on the timeline until I work out
another way?

Many thanks again B!
Re: Tween Class, onEnterFrame blemmo
3/1/2006 1:50:27 PM
I see... Well, you could probably use this:

box_mc.onEnterFrame = function() {
if (_root._currentframe == SOMEFRAMENUMBER) {
var t1:Tween = new Tween(this."_xscale",Strong.easeOut,100,540,1,true);
var t2:Tween = new Tween(this."_yscale",Strong.easeOut,100,540,1,true);
}
}

But be aware that this approach of having all AS in the first frame may only
work with objects that exist in that frame. If box_mc is put on stage later, it
will not be affected from that code.

greets,
blemmo
AddThis Social Bookmark Button