FORUMS: list search recent posts

Loading Tween after SWF

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Peter Mackay
Loading Tween after SWF
on Dec 17, 2009 at 9:22:39 pm

I have a tween event that I want to take place after the SWF has fully loaded. I have written the tween event in AS 3 and it works when you test the movie. I just want to delay it till the page has fully loaded and is on the screen. there is no mouse event that triggers this tween it just starts. Can any one help me with the code to make this happen.


Return to posts index

Marcus Geduld
Re: Loading Tween after SWF
on Dec 17, 2009 at 10:25:27 pm

Here's one way to do it: put your heavy content on frame 2 (or any frame other than one) and add this code to frame 1:


import fl.motion.easing.Quadratic;
import fl.transitions.Tween;

var readout : TextField;
init();

function init() : void
{
stop();
addTextField();
initPreloader();
}

function addTextField() : void
{
readout = new TextField();
readout.text = "loading";
readout.x = stage.stageWidth / 2;
readout.y = stage.stageHeight / 2;
addChild( readout );
}

function initPreloader() : void
{
loaderInfo.addEventListener( ProgressEvent.PROGRESS, preloaderLoop );

}

function preloaderLoop( event : ProgressEvent ) : void
{
var loaded : Number = event.bytesLoaded / event.bytesTotal;
if ( loaded != 1 ) stillLoading( loaded );
else doneLoading();
}

function stillLoading( loaded : Number ) : void
{
readout.text = Math.round( loaded * 100 ) + "%";
}

function doneLoading() : void
{
hideTextField();
stopPreloader();
startAnimation();
}

function hideTextField() : void
{
removeChild( readout );
readout = null;
}

function stopPreloader() : void
{
loaderInfo.removeEventListener( ProgressEvent.PROGRESS, preloaderLoop );
}

function startAnimation() : void
{
var rocket : Rocket = new Rocket();
addChild( rocket );
rocket.x = ( stage.stageWidth / 2 ) - ( rocket.width / 2 );
new Tween( rocket, "y", Quadratic.easeIn,
stage.stageHeight - rocket.height,
-(rocket.height + 30), 2, true );
}


The code assumes that there's a library item called Rocket (the animation) with Export for Actionscript checked.

You can see this here: http://www.grumblebee.com/stuff/cow/delayAnimation.swf'>http://www.grumblebee.com/stuff/cow/http://www.grumblebee.com/stuff/cow/delayAnimation.swf

You can download the source file here: http://www.grumblebee.com/stuff/cow/delayAnimation.fla

Author "After Effects Expressions"
Co-author "After Effects For Flash, Flash For After Effects"
Artistic Director, Folding Chair Classical Theatre, Inc
Senior Flash Developer, Zeitbyte.com


Return to posts index

Peter Mackay
Re: Loading Tween after SWF
on Dec 18, 2009 at 2:51:54 am

Marcus thanks for the reply, your idea of moving the tween code to frame two was the answer for me. It worked like a charm. My code is not as complex as your example. but it works:

//Go get code for tween
import fl.transitions.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;

var genTween = new Tween (genreel_mc, "x", Elastic.easeOut, -235, 96, 4, true);
var autoTween = new Tween (autoreel_mc, "x", Elastic.easeOut, -511, 96, 5, true);
var histTween = new Tween (histreel_mc, "x", Elastic.easeOut, -786, 96, 6, true);
var dpTween = new Tween (dp_mc, "y", Regular.easeOut, 124, 202, 4, true);
var nameTween = new Tween (name_mc, "x", Elastic.easeOut, -156, 101, 4, true);
TransitionManager.start(dp_mc,{type:Fade, direction:Transition.IN, duration:2, easing:Strong.easeIn})
TransitionManager.start(name_mc,{type:Fade, direction:Transition.IN, duration:3, easing:Strong.easeIn})
TransitionManager.start(links_mc,{type:Fade, direction:Transition.IN, duration:4, easing:Strong.easeIn})


this is a learning experience for me and a work ing progress.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]