Groups | Blog | Home
all groups > flash actionscript > february 2007 >

flash actionscript : MX Tween classes and endTween():Void


AKIRA_x
2/11/2007 2:58:12 PM
I have had to use MX tween classes for a project. Later into the project the
need for a skip button was introduced. But as we know once a tween has started
it will run no matter what. So I need to interrupt the tween and make it skip
to the end. I googled and found the endTween function. but I am having trouble
making it work. As I understand the function its supposed to make my tweens
skip to the end and be done. But I am not having any luck. I have made a test
code and could really use some help!

[Q]import mx.transitions.Tween;
import mx.transitions.easing.*;

var square:Object = new Tween(square_mc, "_x", Regular.easeOut, 0, 451, 5,
true);[/Q]

And I try to make this tween skip to the end with a button. I have tried with
alot of different configurations. None of them work. This one here is just the
last. But it dosent work either as stated:

[Q]btn_1.onRelease = function(){
trace("button works");
endTween(square_mc);
}[/Q]
LuigiL
2/11/2007 3:20:00 PM
btn_1.onRelease = function(){
trace("button works");
square.fforward();
}

AKIRA_x
2/11/2007 3:23:56 PM
Sweet!! That did the trick!

Thank you for the help!!

AKIRA_x
2/11/2007 4:16:25 PM
Yeah...I was a bit quick there. That code worked on the test, but not in the
project. It has no effect at all actually.

I got this other code in another forum:

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

var square:Tween = new Tween(square_mc, "_x", Regular.easeOut, 0, 451, 5,
true);

function endTween(ob) {
removeMovieClip(__OnEnterFrameBeacon);
ob.obj[ob.prop] = ob.change;
}

btn_1.onRelease = function() {
trace("button works");
endTween(square);
};

And again it works on the test, but in the project it makes the tween stop
where it is when I click the button. So in the test it makes it skip to the end
of the tween, but in the project it just freezes the tween. strange....

AKIRA
LuigiL
2/11/2007 5:12:52 PM
AKIRA_x
2/11/2007 5:19:23 PM
Here is how the code is in the project. Maybe you can see the problem:

UPDATE: From Kirupa forum I got the tip of declaring the variables outside the
function, and so far that seems to to the trick!! It looks like its working
now. Just ironing out some other bugs..but this seems to work. but under here
is the code as it was. Next post will have the new code.

[code]function build_page(){

var heading_tween:Object = new Tween(heading_container_mc.heading_mc, "_y",
Strong.easeOut, -14.5, 28, 35, true);

var menu_tween:Object = new Tween(menu_txt_mc, "_alpha", Regular.easeOut, 0,
100, 5, true);

var kunde_tween:Object = new Tween(kundecase_mc, "_alpha", Regular.easeOut, 0,
100, 10, true);

meny_mc.play();

trace("Siden er bygget");

}



function endTween(ob) {

trace("endTween running");

removeMovieClip(__OnEnterFrameBeacon);

ob.obj[ob.prop] = ob.change;

}



function skip_intro(){

endTween(heading_tween);

endTween(menu_tween);

endTween(kunde_tween);

trace("nå prøver vi å skippe");

}[/code]



AKIRA

AKIRA_x
2/11/2007 5:20:49 PM
The code that works:

var heading_tween:Object;
var menu_tween:Object;
var kunde_tween:Object;

function build_page(){
heading_tween = new Tween(heading_container_mc.heading_mc, "_y",
Strong.easeOut, -14.5, 28, 35, true);
menu_tween = new Tween(menu_txt_mc, "_alpha", Regular.easeOut, 0, 100, 5,
true);
kunde_tween = new Tween(kundecase_mc, "_alpha", Regular.easeOut, 0, 100, 10,
true);
meny_mc.play();
trace("Siden er bygget");
}

function endTween(ob) {
trace("endTween running");
removeMovieClip(__OnEnterFrameBeacon);
ob.obj[ob.prop] = ob.change;
}

function skip_intro(){
endTween(heading_tween);
endTween(menu_tween);
endTween(kunde_tween);
trace("nå prøver vi å skippe");
}

AKIRA
LuigiL
2/11/2007 5:35:24 PM
If you declare var heading_tween inside a function, the variable is local to
the function and automatically deleted after the function exits. When you then
call endTween(heading_tween); in the function skip_intro(), there is no
reference to heading_tween. A trace in the function endTween() would have told
you that.
function endTween(ob) {
trace(ob);
trace("endTween running");
removeMovieClip(__OnEnterFrameBeacon);
ob.obj[ob.prop] = ob.change;
}

When you declare var heading_tween outside of a function (on a timeline of a
movieclip and called 'a timeline var') the variable won't get deleted and you
can reference it from your code. That's why the code works now.

LuigiL
2/11/2007 5:47:13 PM
You can also rewind the tween. And use fforward() instead of change.



function rewindTween(ob) {
trace("rewindTween running");
removeMovieClip(__OnEnterFrameBeacon);
ob.obj[ob.prop] = ob.rewind();
}

function endTween(ob) {
trace("endTween running");
removeMovieClip(__OnEnterFrameBeacon);
ob.obj[ob.prop] = ob.fforward();
}
AKIRA_x
2/11/2007 6:06:45 PM
Thanks for great input!!

I am not a hardcore programer but I do enjoys this part of flash more and more. And a day you learn something new is a good day indeed!

LuigiL
2/11/2007 7:00:17 PM
AddThis Social Bookmark Button