Loop of random image labels

Hello.  I recently received a code from the blog of David Stiller I like a lot.  It is about how to get a series of labels of image to read in random order without ever repeating.  It's great, and I understand most of the code.

However, when all the labels image have been "played", I don't just go and rest/stop on the last image.  I want that he begin the process again.  Is there a way to do this?  Here is the code that I currently have:

function shuffle(arr:Array):Void {
  var len:Number = arr.length - 1;
  for (var i:Number = len; i >= 0; i--) {
    var p:Number = Math.floor(Math.random() * (i + 1));
    var t:Object = arr[i];
    arr[i] = arr[p];
    arr[p] = t;
  }
}

var labels:Array = ["a", "b", "c", "d", "e"];
shuffle(labels);

var currentLabel:Number = 0;
function gotoNextLabel():Void {
  if (currentLabel < labels.length) {
    gotoAndPlay(labels[currentLabel]);
    currentLabel++;
  } else {
    stop();
  }
}
gotoNextLabel();

Here's the blog entry, I got it from: http://www.quip.net/blog/2007/flash/how-to-jump-randomly-to-frame-labels-without-repeatsht tp: / /

I guess I have to replace 'stop' towards the end with something else, but what?  Repeat?

use:

function shuffle(arr:Array):Void {
  var len:Number = arr.length - 1;
  for (var i:Number = len; i >= 0; i--) {
    var p:Number = Math.floor(Math.random() * (i + 1));
    var t:Object = arr[i];
    arr[i] = arr[p];
    arr[p] = t;
  }
}

var labels:Array = ["a", "b", "c", "d", "e"];
shuffle(labels);

var currentLabel:Number = 0;
function gotoNextLabel():Void {
  if (currentLabel < labels.length) {
    gotoAndPlay(labels[currentLabel]);
    currentLabel++;
  } else {
currentLabel = 0;

shuffle(labels);  //<-if you want to re-randomize labels. otherwise, omit this line

gotoNextLabel();

  }
}
gotoNextLabel();

Tags: Adobe Animate

Similar Questions

  • In Firefox 8.0, why some seemingly random images appear as solid black boxes? These images are available if clicked. (Cache has been compensated; no effect)

    In facebook, images sometimes appear as it should be, and then they gradually move to the black. Although it seems that the affected images are random, images that black initially remain consistent in their behaviour during visits.

    Install the latest version of Flash Player seems to fix all instances of the problem. Thank you for your help.

  • Please help (Urgent), canvas of HTML5 of Random images (no repeat frames) for Adobe animate CC

    I have a very strange problem, I'm a designer, little programming, who now works in HTML5 canvas project.

    I applied the code

    this.btn.addEventListener ("click", fl_MouseClickHandler.bind (this));

    function fl_MouseClickHandler()

    {

    this.gotoAndPlay (Math.round (Math.random () * 5));

    this.gotoAndStop ();

    }

    This code works Random images.

    but my problem is some time by repeating frames occurs.

    Please check my sample

    http://dsrengineering.com/test/Random2.html

    Download File Source (Animate CC)

    http://dsrengineering.com/test/Random2.fla

    If you want to play each image once, randomly selected you can use:

    frameA var = [];

    var index = 0;

    for (var i = 0; i)<>

    frameA.push (i);

    }

    Shuffle (frameA);

    This.BTN... etc

    function fl_MouseClickHandler() {}

    this.gotoAndStop (frameA [index]);

    index ++;

    {if(index>=This.totalFrames)}

    do something. for example, redesign frameA, or not.

    }

    }

    function shuffle (a) {}

    var p;

    var t;

    Ivar var;

    for (ivar =. Length-1; Ivar > = 0; Ivar-) {}

    p = Math.Floor ((Ivar+1) * Math.Random ());

    t = a [ivar];

    a [ivar] = a [p];

    a [p] = t;

    }

    }

  • Display a random image whenever the page is refreshed...

    Hello

    I am creating a website using MUSE. Everything is ready, but there is a prob... I have 200 different images to display on my site. How can I set up to display a random image whenever the page is refreshed?

    You can use the slideshow widget "full screen" on your master page with the following parameters:

  • random image widget

    Does anyone know the calendar of availability or development of a widget for 'random image' triggered by the page refresh or the option to add a currently?

    You can do this by just a basic slideshow.  Drag the images you want to shoot randomly in the gallery.  Click on each item (forward and back arrows, image number display) and remove those.  The gallery will stay without the extras, then set your slideshow to this settings:

    whenever the page refreshes it will randomly pull what appears.  without AutoPlay it will not play another image, without controls or on call there is no user control, so you have an image randomizer

  • Press the button to display a random image

    Hello

    I'm used to working with the timeline and don't often go into the side of the things actionscript.

    I created a second animation 60 an hourglass timer countdown, and next to him, is a map showing a Word. I need this whole animation to play when you press a button 'start game' and also I need the word on the card to be a word at random. All the words are saved as separate vector files for now.

    What is the best way to handle this in the timeline, and what would be the code to display a random image?

    The only discussion I found on these are memory games and they are more complex for what I need!

    I just thought I would put the answer incase anyone needs help with that.

    In the end, I added each image as a picture on the same layer in a clip and added a stop(); action to each image.

    I added this line of code for the keyframe with the movieclip on the timeline:

    This. MovieClipName.gotoAndPlay (Math.round (Math.random () * 4));   4 set up the number of images that you have in the movieclip

    Works great so far - I'll let know you if he throws up additional problems

  • Loader + Math.Random: why is NombrAl not load random images

    Why this code does NOT load a random image, despite the random number of tracing?

    package {}

    import flash.display.Loader;

    import flash.display.Sprite;

    import flash.events. *;

    import flash.net.URLRequest;

    import flash.display.MovieClip;

    SerializableAttribute public class LoaderExampleTwo extends Sprite {}

    public var randomNumber:Number = new Number();

    private var url: String = "D:/flash cs5.5/flash_help_examples/images/"+randomNumber+".jpg";

    public void LoaderExampleTwo() {}

    NombrAl = Math.ceil (Math.random () * 2);

    trace (randomNumber);

    var loader: Loader = new Loader();

    configureListeners (loader.contentLoaderInfo);

    loader.addEventListener (MouseEvent.CLICK, clickHandler);

    var request: URLRequest = new URLRequest (url);

    Loader.Load (request);

    addChild (loader);

    }

    private void configureListeners(dispatcher:IEventDispatcher):void {}

    dispatcher.addEventListener (Event.COMPLETE, completeHandler);

    dispatcher.addEventListener (HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

    dispatcher.addEventListener (Event.INIT, initHandler);

    dispatcher.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);

    dispatcher.addEventListener (Event.OPEN, openHandler);

    dispatcher.addEventListener (ProgressEvent.PROGRESS, progressHandler);

    dispatcher.addEventListener (Event.UNLOAD, unLoadHandler);

    }

    private void completeHandler(event:Event):void {}

    trace ("completeHandler:" + event);

    }

    private void httpStatusHandler(event:HTTPStatusEvent):void {}

    trace ("httpStatusHandler:" + event);

    }

    private void initHandler(event:Event):void {}

    trace ("initHandler:" + event);

    }

    private void ioErrorHandler(event:IOErrorEvent):void {}

    trace ("ioErrorHandler:" + event);

    }

    private void openHandler(event:Event):void {}

    trace ("openHandler:" + event);

    }

    private void progressHandler(event:ProgressEvent):void {}

    trace ("progressHandler: bytesLoaded =" + event.bytesLoaded + "bytesTotal =" + event.bytesTotal);

    }

    private void unLoadHandler(event:Event):void {}

    trace ("unLoadHandler:" + event);

    }

    private void clickHandler(event:MouseEvent):void {}

    trace ("clickHandler:" + event);

    var loader: Loader = Loader (event.target);

    Loader.Unload ();

    }

    }

    }

    Try:

    package {}

    import flash.display.Loader;

    import flash.display.Sprite;

    import flash.events. *;

    import flash.net.URLRequest;

    import flash.display.MovieClip;

    SerializableAttribute public class LoaderExampleTwo extends Sprite {}

    public var randomNumber:Number = new Number();

    private var url: String

    public void LoaderExampleTwo() {}

    NombrAl = Math.ceil (Math.random () * 2);

    trace (randomNumber);

    URL = "D:/flash cs5.5/flash_help_examples/images/"+randomNumber+".jpg";

    var loader: Loader = new Loader();

    configureListeners (loader.contentLoaderInfo);

    loader.addEventListener (MouseEvent.CLICK, clickHandler);

    var request: URLRequest = new URLRequest (url);

    Loader.Load (request);

    addChild (loader);

    }

    private void configureListeners(dispatcher:IEventDispatcher):void {}

    dispatcher.addEventListener (Event.COMPLETE, completeHandler);

    dispatcher.addEventListener (HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

    dispatcher.addEventListener (Event.INIT, initHandler);

    dispatcher.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);

    dispatcher.addEventListener (Event.OPEN, openHandler);

    dispatcher.addEventListener (ProgressEvent.PROGRESS, progressHandler);

    dispatcher.addEventListener (Event.UNLOAD, unLoadHandler);

    }

    private void completeHandler(event:Event):void {}

    trace ("completeHandler:" + event);

    }

    private void httpStatusHandler(event:HTTPStatusEvent):void {}

    trace ("httpStatusHandler:" + event);

    }

    private void initHandler(event:Event):void {}

    trace ("initHandler:" + event);

    }

    private void ioErrorHandler(event:IOErrorEvent):void {}

    trace ("ioErrorHandler:" + event);

    }

    private void openHandler(event:Event):void {}

    trace ("openHandler:" + event);

    }

    private void progressHandler(event:ProgressEvent):void {}

    trace ("progressHandler: bytesLoaded =" + event.bytesLoaded + "bytesTotal =" + event.bytesTotal);

    }

    private void unLoadHandler(event:Event):void {}

    trace ("unLoadHandler:" + event);

    }

    private void clickHandler(event:MouseEvent):void {}

    trace ("clickHandler:" + event);

    var loader: Loader = Loader (event.target);

    Loader.Unload ();

    }

    }

    }

  • Select the random image script

    I create a small movie with a set of random images all appear in the same place (no horizontal or vertical movement). I want each image displayed on the screen for two seconds, then replaced by another image selected at random. There are 17 images in the game. Here is the script I use:

    on enterFrame

    Channel = Random (17)

    _movie. Delay(2*60)

    on exitFrame

    go to the section

    end

    This script works well. However, because the population is small - only 17 - what happens when I run the script is that too often it selects at random the same image once, twice, sometimes up to five times in a row, giving the effect that the film is either stuck or does not properly. I would like to know how to change the script so that on exitFrame it randomly chooses a 16 other pictures but not the current image. At first I thought that if the script read random (16) or random(17-1) that could work, but it doesn't.

    Any thoughts would be welcome.

    Dallas

    Start by adding a script for frameScript channel which stops at the head of this frame. The script that I have provided above should then do the rest.

  • slide show code generating random images with clickable links

    I make a slide show with images that occur randomly wch hav clickable links, OK it works but sometimes, the transition is very fast instead of the 8 s interval I expected, when I discovered the exit trace(), I noticed that sometimes the timer is triggered two times or more at the same time... my code is below... What perhaps may cause well u want to help

    I have 21 pictures with 21 images

    Import fl.transitions.Tween;

    Fl.transitions.easing import. *;

    Import fl.transitions.TweenEvent;

    import flash.events.MouseEvent;

    Stop();   slide stops

    var total_images:Number = 21;

    var my_playback_counter:Number = 0;

    showslide();     call to the showslide function

    defination function with the timer event

    function showslide (): void {}

    var myTimer:Timer = new Timer (8000);

    myTimer.addEventListener (TimerEvent.TIMER, timerListener);

    myTimer.start ();

    }

    / * function timelistener

    After 8 s, meter reading in increments of 1.

    Then reset to 0 playbckcounter if it is equal to total images

    */

    function timerListener (e:TimerEvent): void {}

    my_playback_counter = my_playback_counter + 1;

    If (my_playback_counter == total_images) {}

    my_playback_counter = 0;

    }

    trace ("Timer is triggered"); trace when the timer goes off

    NextImage();

    }

    function NextImage (): void {}

    var pic_number:Number = 21;

    var randomframe:Number = Math.ceil (Math.random () * pic_number) ;// randomly generates betwwen number 1 and 5

    trace (randomframe);

    gotoAndStop (randomframe); display a random image

    }

    Button1.addEventListener (MouseEvent.CLICK, onMouseClickB1);

    function onMouseClickB1(e:MouseEvent):void {}

    var request: URLRequest = new URLRequest ("http://www.aginternetwork.org/en/");

    navigateToURL (request, "_blank");

    }

    new Tween(btn1,"alpha",None.easeOut,0,1,1,true);

    Each time the playhead returns to frame where this code is another instance of Timer will be created.  Try to put a conditional on the showslide function call so that he will not repeat...

    var showStarted:Boolean; by assigning not it is null or false

    {if(!showStarted)}

    showslide()

    showStarted = true; but once they assign remains true

    }

  • Random image display

    I want to display Let's say 3 random images out of 6 images. Whenever I click on a button, I should have a screen of 3 unique random images.

    All what I know and understand is what follows. My XML file has 6 images. I know that I need the shuffle function to get the desired result, but I don't know how.

    The script below will draw only all or one of them, that's all. It is the part of math that I don't understand. I thought I'll give it another shot, before I decide to take another hobby,... like to play soccer with my crazy rottweiller.

    Sam

    var myXML:XML;
    var myLoader:URLLoader = new URLLoader();
    myLoader.load (new URLRequest ("jamilou.xml"));
    myLoader.addEventListener (Event.COMPLETE, processXML);
    function processXML(e:Event):void
    {
    myXML = new XML (e.target.data);
    trace(myXML.image.*);
    }

    you do not set your chargers and you do not add the shuffle() function correctly:

    var imageA:Array = [];

    var loader1:Loader = new Loader();

    addChild (loader1);

    var loader2:Loader = new Loader();

    addChild (loader2);

    var loader3:Loader = new Loader();

    addChild (loader3);
    loader2.x = 200;

    loader3.x = 400;

    var myXML:XML;
    var myLoader:URLLoader = new URLLoader();
    myLoader.load (new URLRequest ("jamilou.xml"));
    myLoader.addEventListener (Event.COMPLETE, processXML);
    function processXML(e:Event):void
    {
    myXML = new XML (e.target.data);

    for (var i: int = 0; i
    {

    imageA.push (new URLRequest (myXML.IMAGE [i]));

    }

    yourbutton.enabled = true;

    }

    yourbutton.addEventListener (MouseEvent.CLICK, clickF);

    yourbutton. Enabled = false;

    function clickF(e:MouseEvent):void
    {

    Shuffle (image);

    loader1. Load(imageA[0]);

    loader2. Load(imageA[1]);

    loader3. Load(imageA[2]);


    }

    function shuffle(imageA:Array)
    {
    var p:int;
    var t: *;
    var ivar:int;
    for (ivar = imageA.length - 1; ivar > = 0; ivar-)
    {
    p = Math.Floor ((Ivar+1) * Math.Random ());
    t = UIImage [ivar];
    Imageo [ivar] = UIImage [p];
    Imageo [p] = t;
    }

    }

  • Using random image loader, please

    Hi all
    I'm looking by using a random image loader, to load external images files by using the following code:

    pic_arr = [' dhi/1', ' dhi/2', ' dhi/3', ' dhi/4', ' dhi/5'];

    onLoad = function() {}

    ranNum = Math.floor (Math.random () * pic_arr.length);

    randomLoaderMc.loadMovie (pic_arr [ranNum] + '.jpg');

    };

    Did anyone know how I can do this, so it will never load the same image twice in a row?

    Thanks in advance
    Rich

    first create the table

    var pic_arr = new Array ("dhi/1", "dhi/2", "dhi/3", "dhi/4", "dhi/5", "6/dhi");

    function shuffle (a) {}

    var len is. Length-1;

    for (i = len; I > = 0; i--) {}

    var percent = Math.floor (Math.random () *(i+1));

    var t = [i];

    a [i] = a [p];

    a [p] = t;

    }

    return a;

    }

    Then alternate the benefits

    picArray = shuffle (picArray);

  • Random image with link

    Hey guys, I'm using a random image code, but when I preview the page I have a red X in the left corner of the where the image is supposed to be, but it is still clickable and it goes to the file I linked to. Here is the code

    < script language = "JavaScript" >
    <!-hide from older browsers


    var imagenumber = 5;
    var NombrAl = Math.Random ();
    var rand1 = Math.round ((imagenumber-1) * NombrAl) + 1;
    images = new Array
    images [1] = "IMAGE #1".
    images [2] = "IMAGE #2".
    images [3] = "IMAGE #3".
    images [4] = "IMAGE #4".
    images [5] = "IMAGE #5".
    var image = images [rand1]

    Links = new Array
    links [1] = "LINK #1".
    links [2] = "LINK #2".
    links [3] = "LINK #3".
    links [4] = "LINK #4".
    links [5] = "LINK #5".
    var = links [rand1] link
    -End hide here->

    < /script >

    Here's the code for body

    < script language = "JavaScript" >
    <!-hide the script from older browsers.
    document. Write (' < A HREF = "' + link + '" > < IMG SRC = "' + image + '" border = "0" > < /a > ')
    -End hide here->
    < /script >

    I know your picutres are there, why not try this, after the =, right-click, select Code Hint tools | URL browser and use the tool to link the images.

    You listed as Pictures\Accounting Cartoon1.jpg, the slash is false, then let DW set the path and the file for you.

    Gary

  • For loop in place, images to scale and move

    I have an image which I enclose, is the white part of the image (I recorded it on a black background so it is easy to see, but it's on a transparent background, saved as a gif file and imported to flash). When my for loop runs, I'm trying to put this image on stage by programming, but it seems that it is not doing things. It will scale the image and positioned some in all directions

    I wanted the images (8) appears in 2 columns each staggered regularly, but he fails to do so. The clip holds the image below. Since it is an irregular shape, it also seems to make the edges really rough.

    (1) why is the loop generating these images in all directions like this?

    (2) it would be more ideal to draw this shape with flash, rather than by using a gif image? Such a form is even possible to draw?

    This is the code:

    Fl.transitions import. *;
    Fl.transitions.easing import. *;
    import flash.events.TimerEvent;

    var imageLoader:Loader;

    var xmlData:XML;

    var bucketItem:MovieClip; They hold the attached picture
    var bucketHor:MovieClip;

    placeBuckets();

    public function set {loadedXML(xml:XML):void}
    xmlData = xml;
    }

    function placeBuckets (): void {}
    var all: Number = 50;
    After var: number = 115;

    var bucketCount:XMLList = xmlData.product;
    for (var u: uint = 0; u < bucketCount.length (); u ++) {}
    bucketItem = new bucket();
    bucketHor = new bucketr();

    If (bucketCount.country.text ([u]) == 'USA') {}
    1st = bucketItem.y;
    bucketItem.x = 100;
    var bucketTween:Tween = new Tween (bucketItem, "x", Regular.easeOut, bucketItem.x, 0, 0.5, true);
    } else {}
    bucketHor.y = after;
    bucketHor.x = 300;
    bucketItem.scaleX = - 1;
    var buckettwoTween:Tween = new Tween (bucketItem, "x", Regular.easeOut, bucketItem.x, 0, 0.5, true);
    }
    var bucketImgTrans = new TransitionManager (bucketItem);
    bucketImgTrans.startTransition ({type: Zoom, direction: Transition.IN, duration: 3, easing:Strong.easeOut});})
    var bucketImgTransH = new TransitionManager (bucketHor);
    bucketImgTransH.startTransition ({type: Zoom, direction: Transition.IN, duration: 3, easing:Strong.easeOut});})
    trace (bucketItem.y);

    trace (bucketHor.y);
    addChildAt (bucketItem, 0);
    addChildAt (bucketHor, 0);
    After = (after + 200) - 115;
    1st (1st + 130) = - 50;
    }
    }

    It's the Stmt trace for two position there of bucket

    0
    115
    0
    200
    0
    285
    0
    370
    370
    0
    450
    0
    530
    0
    610
    0

    Regarding graphic design, here is the code (not exactly like yours but you can make adjustments - discover the documentation Flash Graphics class):

    var sp:Sprite = new Sprite();
    var gr:Graphics = sp.graphics;
    gr.beginFill(0xff0000);
    gr.moveTo(0, 0);
    gr.lineTo(213, 5);
    gr.lineTo(213, 65);
    gr.lineTo(6, 75);
    gr.lineTo(0, 0);
    gr.endFill();
    addChild(sp);
    

    In regards to the positioning, what are these classes/symbols backet and baketr?

    		   
  • Random image work but still get error

    Hello

    My random image generation works but occasionally an error message came out as follows: -.

    Error #2007: Request parameter must be non-null.

    Here is my code: -.

    var ImgReq01:URLRequest = new URLRequest("images/random/image01.jpg");
    var ImgReq02:URLRequest = new URLRequest("images/random/image02.jpg");
    var ImgReq03:URLRequest = new URLRequest("images/random/image03.jpg");
    var ImgReq04:URLRequest = new URLRequest("images/random/image04.jpg");

    var imgList:Array is [ImgReq01, ImgReq02, ImgReq03, ImgReq04];.

    var imgRandom = imgList [Math.floor (Math.random () * imgList.length - 1)];

    var imgLoader:Loader = new Loader();
    imgLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, onComplete);
    imgLoader.load (imgRandom);

    function onComplete(event:Event):void
    {
    var randomImage:Bitmap = Bitmap (imgLoader.content);
    randomImage.x =-203;
    randomImage.y =-280;
    addChild (randomImage);
    event.currentTarget.removeEventListener (Event.COMPLETE, onComplete);
    }

    I understand no no matter who might shed light on why I get this error message?

    Thank you very much

    the line:

    var imgRandom = imgList [Math.floor (Math.random () * imgList.length - 1)];

    is the place where it fails.

    Math.Random () returns a value between 0 and 1. Including zero, excluding 1.

    Multiply it by the length of the results list something between 0 and something less than the length of the list.

    subtract 1 and you have something less than zero.

    That should do it

    var imgRandom = imgList [Math.floor (Math.random () * imgList.length)];

    No subtraction, just rounding down. Thus, he never returned a number being the length of the table prevent errors on this end. It will never be less than zero because Math.Random () returns nothing less than zero errors preventing on this end.

  • Random Image Script need with links

    I need a script for random images on my home page. I need the image to have its own link depending on which image is displayed. I would like a script php (no database) if possible

    I thought about it by doing a random include

    <>
    srand (Time ());
    $random = (rand () %3);
    require_once("./$random.php");
    ?>

Maybe you are looking for