I'm working on this animation that contains about a hundred images. I could make the images to play sequentially, but I need them to play randomly. Could anyone help me out w/ this?
this might not be the easiest way, but I might set up 2 arrays, one with the frame number the images start on, and the other with the frame number the images end on.. so it will randomly call and gotoAndPlay the first array, at the same time check for when that particular index has reached its ending frame, then it will scrap it, and gotoAndPlay a new index in the first array.. That is, if you have already set your animation as a timline animation, you weren't to clear on that..
for this, I had three timeline tweens. it started on frame two and this script was on frame 1. This is AS2 by the way. Rothrock: If you happen to stop by, yes, this time I made it less confusing by adding this, ASSetPropFlags(Array.prototype, ["shuffle"], 1, 1); in by default. stop(); Array.prototype.shuffle = function() { for (var ivar = this.length-1; ivar>=0; ivar--) { var p = random(ivar+1); var t = this[ivar]; this[ivar] = this[p]; this[p] = t; } }; ASSetPropFlags(Array.prototype, ["shuffle"], 1, 1); var Start_ar:Array = new Array(2, 22, 43); var End_ar:Array = new Array(21, 42, 63); Start_ar.shuffle(); index = 0; function play_random() { for (var i = 0; i<Start_ar.length; i++) { Start_ar[i].ivar = i; gotoAndPlay(Start_ar[i]); var checkFrame = setInterval(checking, 300); function checking() { if (_root._currentframe>=[End_ar[this.ivar]]) { load_random(); } } } if (index == Start_ar.length) { (index=0); } } play_random()
Thanks for the info. Sorry about not being able to clarify what I was trying to do. It's just driving me a little crazy. I was trying to have an empty mc w/ some ActionScript to call the images out from a folder in my desktop. Could I do that w/ arrays? Could you also give me some code samples if possible?
.. import mx.transitions.easing.Strong; import mx.transitions.Tween; Array.prototype.shuffle = function() { for (var ivar = this.length-1; ivar>=0; ivar--) { var p = random(ivar+1); var t = this[ivar]; this[ivar] = this[p]; this[p] = t; } }; ASSetPropFlags(Array.prototype, ["shuffle"], 1, 1); var Image_ar:Array = new Array("image1.png", "image2.png", "image3.png", "image4.png"); Image_ar.shuffle(); index = 0; function load_random() { if (index == Image_ar.length) { (index=0); } var mcLoader:MovieClipLoader = new MovieClipLoader(); var listener:Object = new Object(); listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void { yourMc._alpha = 0; }; mcLoader.addListener(listener); mcLoader.loadClip(Image_ar[index++], yourMc); listener.onLoadComplete = function(yourMc:MovieClip):Void { var tw:Tween = new Tween(yourMc, "_alpha", Strong.easeOut, 0, 100, 1, true); }; } load_random(); var myInterval = setInterval(load_random, 3000);
here is another example using a different strategy: // i did not take the liberty of setting you up to load external pics. i used // attachMovie in combination with an array of pics stored in the library to show you // how this method works. // you can tweek the code to load external pics quite easily.
Don't see what you're looking for? Try a search.
|