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?
Page 1 of 1
AS3 Starting or delaying a frames start
#2
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
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
Share this topic:
Page 1 of 1
Help















