flash actionscript:
how do i load a movie clip after a certain amount of time has elapsed? i have been playing with onEnterFrame and setInterval with no results. basically i want to attach a movie in certain location after about a half-second upon loading of a frame. thanks > mark
function loader() { _root.createEmptyMovieClip("holder",1); holder.attachMovie("yourMovie",yourMovie,1); clearInterval(loadIt) }
thank you. after fiddling around this script worked also... attachMovie("patch_level1_mc", "patch_level1_mc", 2, {_x:510, _y:350}); patch_level1_mc._alpha = 0; attachPatch = function () { patch_level1_mc._alpha = 100; } setInterval(attachPatch, 500); clearInterval();
it is probably a better idea to ensure that the interval has an id... either as given by lummeeguvnor or else an object... this will ensure the correct interval is removed... with the code you provided, you are still attaching the instance straight away just setting it's alpha to zero... that isn't what you asked for. try something like this: this.intervalId = setInterval(attachPatch= function(patch,clip){ intervalCounter++; clip.attachMovie(patch,patch,intervalCounter); clearInterval(clip.intervalId) },500,"patch_level1_mc",this); I think that is the right code. cheers,
Just a comment... I don't see the need for intervalCounter seeing that the interval is only called once...And since your putting your function directly inside the setInterval there's no point in naming it... personally I would make the function outside the setInterval for reading purposes. And if you want to make a method for doing this, you could do something like: MovieClip.prototype.waitAttachMovie = function(delay, idName, newName, depth, initObject){ if(!this.intervals){ this.intervals = []; this.attachPatch = function(mc,idName,newName,depth,initObject,idLoc)){ mc.attachMovie(idName,newName,depth,initObject); clearInterval(mc.intervals[idLoc]); } } var idLoc = this.intervals.length; this.intervals.push(setInterval(this.attachPatch,500,this,idName,newName,depth, initObject,idLoc)); } //then use: this.waitAttachMovie(500,"patch_level1_mc", "patch_level1_mc", 2, {_x:510, _y:350}); but of course if you're only doing it once, the old code worked fine... BTW, I haven't tested the code, but it mite work.
Don't see what you're looking for? Try a search.
|