Web Design Forum: AS3 Starting or delaying a frames start - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

AS3 Starting or delaying a frames start Rate Topic: -----

#1 User is offline   s_ainley87 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 99
  • Joined: 12-May 08
  • Reputation: 0
  • Experience:Beginner
  • Area of Expertise:Designer/Coder

Posted 02 September 2008 - 09:30 AM

Hello,

I am currently trying to a swf starting to play the moment the webpage has stopped loading, I have come up with two solutions, one is to add a new frame that has a play button and an event listerner, the other is too some how hold the playing of the movie for say 5 seconds. I am new to actionscript 3 but would prefer to use it. Does any one have any ideas?
0

#2 User is offline   Roberto 

  • Rain Dog
  • PipPipPipPip
  • Group: Members
  • Posts: 532
  • Joined: 19-August 07
  • Reputation: 2
  • Gender:Male
  • Location:Suffolk
  • Experience:Intermediate
  • Area of Expertise:Coder

Posted 02 September 2008 - 11:01 AM

Hello

One approach could be to use a listener for the Event.COMPLETE, which fires when the swf has fully loaded. From within that function you can move to the next frame or start a TimerEvent.Timer to delay the start of the movie. You can also make use of the ProgressEvent.PROGRESS to let the user know something is happening. These need to go on Frame one. As an example :

stop();

MovieClip(root).loaderInfo.addEventListener(ProgressEvent.PROGRESS, abitHasLoaded);
MovieClip(root).loaderInfo.addEventListener(Event.COMPLETE, allLoaded);


function abitHasLoaded(e:ProgressEvent):void {

//get the percentage of how much of the movie is loaded
var percentLoaded:Number = e.bytesLoaded / e.bytesTotal * 100;
//You could update a dynamic text box or move frames in a movieClip to show loading is going on
trace(percentLoaded);
}

function allLoaded(event:Event):void {

MovieClip(root).loaderInfo.removeEventListener(ProgressEvent.PROGRESS, abitHasLoaded);
MovieClip(root).loaderInfo.removeEventListener(Event.COMPLETE, allLoaded);

//Start movie on next frame
MovieClip(root).gotoAndPlay(2);
}

If you are looping your movie, put a this.gotoAndPlay(2); on the last frame - this will miss out the first frame, which has a stop(); in it.

If you want to add a delay once the movie has loaded:

stop();


//set the timer - 1000 == 1 sec
var timer:Timer = new Timer(5000);

//set a function to be called on each timer event
timer.addEventListener(TimerEvent.TIMER, startMovie);

//call this function when movie fully loaded
MovieClip(root).loaderInfo.addEventListener(Event.COMPLETE,allLoaded);

function startMovie(e:TimerEvent):void {

timer.stop();
//start on the next frame
MovieClip(root).gotoAndPlay(2);


}

function allLoaded(event:Event):void {

//remove eventListener
MovieClip(root).loaderInfo.removeEventListener(Event.COMPLETE, allLoaded);

//Start the Timer
timer.start();
}

Rob
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users