I have this code that is supposed to move a movieclip once loaded. It is loading into the initial position but doesn't then trigger the onEnterFrame ///////////////////////////// var easing = 0.2; var targX = -10; var targY = 250; ///////////////////////////// namesArray = new Array("bg", "widget1", "widget2", "widget3", "MainLogo", "MainMessage"); locationsArray = new Array([0, 0], [-500, 250], [275, 225], [445, 250], [530, 105], [410, 23]); for (i=0; i<namesArray.length; i++) { container_mc.createEmptyMovieClip(namesArray[i]+"_mc", i); container_mc[namesArray[i]+"_mc"]._x = locationsArray[i][0]; container_mc[namesArray[i]+"_mc"]._y = locationsArray[i][1]; if (i == 0) { container_mc[namesArray[i]+"_mc"].loadMovie("images/"+namesArray[i]+".jpg"); } else { container_mc[namesArray[i]+"_mc"].loadMovie("images/"+namesArray[i]+".swf"); } } ////////////////////////////// container_mc.widget1_mc.onEnterFrame = ease; function ease() { var dx = targX-this._x; var dy = targY-this._y; if (Math.abs(dx)<1) { this._x = targX; this._y = targY; delete onEnterFrame; trace("done"); } else { var vx = dx*easing; var vy = dy*easing; this._x += vx; this._y += vy; } } //////////////////////////////
Well, in the meantime I quickly edited your original code. You have to wait for the image or swf to load before you can invoke a function that performs the easing. I'm using the MovieClipLoader Class here. Now, replace the names in the names_array (I used some of my own images obviously). And I did not use a container_mc but created the container on the root. In the code I'm passing the container to the function doEase() so all images are now eased to the same spot (just as an example, you can change that). And, the onEnterFrame keeps running - you just need to use this.onEnterFrame there (when you create the container on the root. var loader:MovieClipLoader=new MovieClipLoader(); var listener:Object=new Object(); listener.onLoadInit=function(target:MovieClip):Void{ doEase(target); } loader.addListener(listener); ///////////////////////////// var easing = 0.2; var targX = -10; var targY = 250; ///////////////////////////// namesArray = new Array("01", "02", "03", "04", "05", "06"); locationsArray = new Array([0, 0], [-500, 250], [275, 225], [445, 250], [530, 105], [410, 23]); for (var i=0; i<namesArray.length; i++) { //create a clip on the root using a reference var container:MovieClip=this.createEmptyMovieClip("mc"+namesArray[i]+"_mc", i); container._x = locationsArray[i][0]; container._y = locationsArray[i][1]; if (i == 0) { loader.loadClip("images/"+namesArray[i]+".jpg",container); } else { loader.loadClip("images/"+namesArray[i]+".jpg",container); } } ////////////////////////////// function doEase(target:MovieClip):Void{ target.onEnterFrame = ease; function ease() { var dx = targX-this._x; var dy = targY-this._y; if (Math.abs(dx)<=1) { this._x = targX; this._y = targY; delete this.onEnterFrame; trace("done"); } else { var vx = dx*easing; var vy = dy*easing; this._x += vx; this._y += vy; } } } //////////////////////////////
nothing. I changed the array names back since these are the names of the files I am trying to load into the movieclips here is what I did namesArray = new Array("bg", "widget1", "widget2", "widget3", "MainLogo", "MainMessage"); locationsArray = new Array([0, 0], [-500, 250], [275, 225], [445, 250], [530, 105], [410, 23]); for (var i=0; i<namesArray.length; i++) { //create a clip on the root using a reference var container:MovieClip=this.createEmptyMovieClip(namesArray[i]+"_mc", i); container._x = locationsArray[i][0]; container._y = locationsArray[i][1]; if (i == 0) { loader.loadClip("images/"+namesArray[i]+".jpg",container.namesArray[i]+"_mc"); } else { loader.loadClip("images/"+namesArray[i]+".swf",container.namesArray[i]+"_mc"); } }
when I use loadClip nothing loads but if I do tis everything appears on the stage but doesn't trigger the onEnterFrame namesArray = new Array("bg", "widget1", "widget2", "widget3", "MainLogo", "MainMessage"); locationsArray = new Array([0, 0], [-500, 250], [275, 225], [445, 250], [530, 105], [410, 23]); for (i=0; i<namesArray.length; i++) { container_mc.createEmptyMovieClip(namesArray[i]+"_mc", i); container_mc[namesArray[i]+"_mc"]._x = locationsArray[i][0]; container_mc[namesArray[i]+"_mc"]._y = locationsArray[i][1]; if (i == 0) { container_mc[namesArray[i]+"_mc"].loadMovie("images/"+namesArray[i]+".jpg"); } else { container_mc[namesArray[i]+"_mc"].loadMovie("images/"+namesArray[i]+".swf"); } }
tjohnson4@gmail.com but my work computer currently uses MX
Oops, my bad. MX doesn't support MovieClipLoader (MX2004 does). Well, the you will need to preload the jpg's and swf's and use the getBytesLoaded() and getBytesTotal() methods. Otherwise your onEnterFrame won't work.
i took this code from the actionScript 1 dictionary here
I don't understand how to preload the jpg's and swf's and use the getBytesLoaded() and getBytesTotal() methods. Could you give me a little more insight
Don't see what you're looking for? Try a search.
|