Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    95
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Create a random image changing script

    Hi, I want to create a script that randomly selects one image from a set of images and then fades into another random image from the set of images. Does anyone know of a script that exists that does this or something close to it?

  • #2
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Hi! Alexmel

    ..I´ll been searching for the same thing,
    then I found this:

    http://www.codingforums.com/showthread.php?t=129968

    Now I need this get to work on my handset
    nokia 6300 with flashlite 2.0

    Don't work as screensaver!!

    It seems that the problem is in the xml file (The phone only
    reads the swf file) , although
    plays well every time I openup normally..

    I need some help

  • #3
    New Coder
    Join Date
    Dec 2008
    Posts
    95
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Awesome, thanks Aldo. Can anyone help me modify this script so that instead of one set of pictures that crossfade into each other, I can have several picture holders that crossfade one picture into another, then randomly select another picture holder to crossfade a picture, etc. It would be set up like the pic below:


  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Hmm that would be a lot of code changes.

    Are you wanting to create all of the movieClips with actionscript or are they already created on the stage?

    You'll have to have some kind of function to select a random frame first, which depends on how you have (or want) to setup the containers.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    New Coder
    Join Date
    Dec 2008
    Posts
    95
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I haven't set up any of the movie clips yet. I didn't want to start without knowing the best way to approach this. Essentially all I have is my saved pictures and an empty fla.

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Good stuff.

    Ok then. First task, creation of 8 movieClip holders. You interesting in tackling this yourself and posting your progress? I'll help!

    Lets do it all with actionscript. Its more fun.

    http://livedocs.adobe.com/flash/8/ma...=00001394.html

    This is some information about how to create a container movieClip. Task #1 is to replicate it so there are 8 displayed, and also they need to be positioned and sized (._y, ._x, ._width, ._height)
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    New Coder
    Join Date
    Dec 2008
    Posts
    95
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thank you for taking the time to help me and aid me in learning actionscript. Here is what I have so far:

    Code:
    _root.createEmptyMovieClip("box1_mc", 1);
    	box1_mc._x = 100;
    	box1_mc._y = 0 ;
    	box1_mc._width = 166;
    	box1_mc._height = 126;
    _root.createEmptyMovieClip("box2_mc", 2);
    	box2_mc._x = 315;
    	box2_mc._y = 0;
    	box2_mc._width = 166;
    	box2_mc._height = 126;
    _root.createEmptyMovieClip("box3_mc", 3);
    	box3_mc._x = 540;
    	box3_mc._y = 0;
    	box3_mc._width = 166;
    	box3_mc._height = 126;
    _root.createEmptyMovieClip("box4_mc", 4);
    	box4_mc._x = 100;
    	box4_mc._y = 155;
    	box4_mc._width = 166;
    	box4_mc._height = 126;
    _root.createEmptyMovieClip("box5_mc", 5);
    	box5_mc._x = 540;
    	box5_mc._y = 155;
    	box5_mc._width = 166;
    	box5_mc._height = 126;
    _root.createEmptyMovieClip("box6_mc", 6);
    	box6_mc._x = 100;
    	box6_mc._y = 310;
    	box6_mc._width = 166;
    	box6_mc._height = 126;
    _root.createEmptyMovieClip("box7_mc", 7);
    	box7_mc._x = 315;
    	box7_mc._y = 310;
    	box7_mc._width = 166;
    	box7_mc._height = 126;
    _root.createEmptyMovieClip("box8_mc", 8);
    	box8_mc._x = 540;
    	box8_mc._y = 310;
    	box8_mc._width = 166;
    	box8_mc._height = 126;

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Perfect. Now we need to load a set of images. There is a good example in the thread posted above, and here is a tutorial. Basically you need to load the images from XML into an array so we can then assign them randomly.

    http://www.kirupa.com/web/xml/XMLwithFlash3.htm
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #9
    New Coder
    Join Date
    Dec 2008
    Posts
    95
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Like this?

    Code:
    _root.createEmptyMovieClip("box1_mc", 1);
    	box1_mc._x = 100;
    	box1_mc._y = 0;
    	box1_mc._width = 166;
    	box1_mc._height = 126;
    	
    _root.createEmptyMovieClip("box2_mc", 2);
    	box2_mc._x = 286;
    	box2_mc._y = 0;
    	box2_mc._width = 166;
    	box2_mc._height = 126;
    _root.createEmptyMovieClip("box3_mc", 3);
    	box3_mc._x = 472;
    	box3_mc._y = 0;
    	box3_mc._width = 166;
    	box3_mc._height = 126;
    	
    _root.createEmptyMovieClip("box4_mc", 4);
    	box4_mc._x = 100;
    	box4_mc._y = 167;
    	box4_mc._width = 166;
    	box4_mc._height = 126;
    	
    _root.createEmptyMovieClip("box5_mc", 5);
    	box5_mc._x = 472;
    	box5_mc._y = 167;
    	box5_mc._width = 166;
    	box5_mc._height = 126;
    	
    _root.createEmptyMovieClip("box6_mc", 6);
    	box6_mc._x = 100;
    	box6_mc._y = 334;
    	box6_mc._width = 166;
    	box6_mc._height = 126;
    	
    _root.createEmptyMovieClip("box7_mc", 7);
    	box7_mc._x = 286;
    	box7_mc._y = 334;
    	box7_mc._width = 166;
    	box7_mc._height = 126;
    	
    _root.createEmptyMovieClip("box8_mc", 8);
    	box8_mc._x = 472;
    	box8_mc._y = 334;
    	box8_mc._width = 166;
    	box8_mc._height = 126;
    
    xmlImages = new XML();
    xmlImages.ignoreWhite = true;
    xmlImages.onLoad = loadImages;
    xmlImages.load("images.xml");
    
    function loadImages(loaded) {
    	if (loaded) {
    		xmlFirstChild = this.firstChild;
    		imageFileName = [];
    		totalImages = xmlFirstChild.childNodes[0].childNodes.length;
    		for (i=0; i<totalImages; i++) {
    			imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
    		}
    		randomImage();
    	}
    }

  • #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Good now you can trace the values to see if things are there correctly. Right now its going to also try to call randomImage() which isn't there, so it will cause errors at the moment.

    Code:
    function loadImages(loaded) {
    	if (loaded) {
    		xmlFirstChild = this.firstChild;
    		imageFileName = [];
    		totalImages = xmlFirstChild.childNodes[0].childNodes.length;
    		for (i=0; i<totalImages; i++) {
    			imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
    		}
    		trace(imageFileName[i]); // Should give you the file name for each image in the trace window
    	}
    }
    Now from here we'll have to create a custom function. I guess I need to know how many images you'll have (approx.) and how you want to select them (randomly of course, but should all images be displayed before recycling or does it matter?)
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #11
    New Coder
    Join Date
    Dec 2008
    Posts
    95
    Thanks
    7
    Thanked 0 Times in 0 Posts
    When I run it, the only output is "undefined". I have 65 images which I would like to be used before recycling. Here is my code:

    Code:
    _root.createEmptyMovieClip("box1_mc", 1);
    	box1_mc._x = 100;
    	box1_mc._y = 0;
    	box1_mc._width = 166;
    	box1_mc._height = 126;
    	
    _root.createEmptyMovieClip("box2_mc", 2);
    	box2_mc._x = 286;
    	box2_mc._y = 0;
    	box2_mc._width = 166;
    	box2_mc._height = 126;
    _root.createEmptyMovieClip("box3_mc", 3);
    	box3_mc._x = 472;
    	box3_mc._y = 0;
    	box3_mc._width = 166;
    	box3_mc._height = 126;
    	
    _root.createEmptyMovieClip("box4_mc", 4);
    	box4_mc._x = 100;
    	box4_mc._y = 167;
    	box4_mc._width = 166;
    	box4_mc._height = 126;
    	
    _root.createEmptyMovieClip("box5_mc", 5);
    	box5_mc._x = 472;
    	box5_mc._y = 167;
    	box5_mc._width = 166;
    	box5_mc._height = 126;
    	
    _root.createEmptyMovieClip("box6_mc", 6);
    	box6_mc._x = 100;
    	box6_mc._y = 334;
    	box6_mc._width = 166;
    	box6_mc._height = 126;
    	
    _root.createEmptyMovieClip("box7_mc", 7);
    	box7_mc._x = 286;
    	box7_mc._y = 334;
    	box7_mc._width = 166;
    	box7_mc._height = 126;
    	
    _root.createEmptyMovieClip("box8_mc", 8);
    	box8_mc._x = 472;
    	box8_mc._y = 334;
    	box8_mc._width = 166;
    	box8_mc._height = 126;
    
    xmlImages = new XML();
    xmlImages.ignoreWhite = true;
    xmlImages.onLoad = loadImages;
    xmlImages.load("images.xml");
    
    function loadImages(loaded) {
    	if (loaded) {
    		xmlFirstChild = this.firstChild;
    		imageFileName = [];
    		totalImages = xmlFirstChild.childNodes[0].childNodes.length;
    		for (i=0; i<totalImages; i++) {
    			imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
    		}
    		randomImage();
    	}
    }
    
    function loadImages(loaded) {
           if (loaded) {
                   xmlFirstChild = this.firstChild;
                   imageFileName = [];
                   totalImages = xmlFirstChild.childNodes[0].childNodes.length;
                   for (i=0; i<totalImages; i++) {
                           imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
                   }
                   trace(imageFileName[i]); // Should give you the file name for each image in the trace window
           }
    }

  • #12
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Do you have an XML file like the one exemplified in the same folder as your FLA? You should make one and put it in there, and if you have one already post a few lines of it. Something isn't getting picked up.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #13
    New Coder
    Join Date
    Dec 2008
    Posts
    95
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I have it in the same folder as my FLA. My pics are in a subfolder called "pics". Here is the code:

    Code:
    <xml>
    <images>
    <a title = "pics/adirondack1.jpg" />
    <b title = "pics/cayugaboces1.jpg" />
    <c title = "pics/OU1.jpg" />
    <d title = "pics/questar1pic1.jpg" />
    <e title = "pics/stlawrencelewis1.jpg" />
    <f title = "pics/tst1.jpg" />
    <g title = "pics/WFL1.jpg" />
    <h title = "pics/orleansniagra1.jpg" />
    </images>
    </xml>

  • #14
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Well right now you have two loadImages functions, I didn't catch that last time...duh. You should remove the first one without the trace() statements for the moment, but keep a copy of it! Does that make it work?
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #15
    New Coder
    Join Date
    Dec 2008
    Posts
    95
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I tried that and I still get "undefined" as the output. Maybe it's the way I have things set up? I have an empty frame on the first frame of the root timeline where I'm putting all my actionscript. Here is the revised code:

    Code:
    _root.createEmptyMovieClip("box1_mc", 1);
    	box1_mc._x = 100;
    	box1_mc._y = 0;
    	box1_mc._width = 166;
    	box1_mc._height = 126;
    	
    _root.createEmptyMovieClip("box2_mc", 2);
    	box2_mc._x = 286;
    	box2_mc._y = 0;
    	box2_mc._width = 166;
    	box2_mc._height = 126;
    _root.createEmptyMovieClip("box3_mc", 3);
    	box3_mc._x = 472;
    	box3_mc._y = 0;
    	box3_mc._width = 166;
    	box3_mc._height = 126;
    	
    _root.createEmptyMovieClip("box4_mc", 4);
    	box4_mc._x = 100;
    	box4_mc._y = 167;
    	box4_mc._width = 166;
    	box4_mc._height = 126;
    	
    _root.createEmptyMovieClip("box5_mc", 5);
    	box5_mc._x = 472;
    	box5_mc._y = 167;
    	box5_mc._width = 166;
    	box5_mc._height = 126;
    	
    _root.createEmptyMovieClip("box6_mc", 6);
    	box6_mc._x = 100;
    	box6_mc._y = 334;
    	box6_mc._width = 166;
    	box6_mc._height = 126;
    	
    _root.createEmptyMovieClip("box7_mc", 7);
    	box7_mc._x = 286;
    	box7_mc._y = 334;
    	box7_mc._width = 166;
    	box7_mc._height = 126;
    	
    _root.createEmptyMovieClip("box8_mc", 8);
    	box8_mc._x = 472;
    	box8_mc._y = 334;
    	box8_mc._width = 166;
    	box8_mc._height = 126;
    
    xmlImages = new XML();
    xmlImages.ignoreWhite = true;
    xmlImages.onLoad = loadImages;
    xmlImages.load("images.xml");
    
    function loadImages(loaded) {
           if (loaded) {
                   xmlFirstChild = this.firstChild;
                   imageFileName = [];
                   totalImages = xmlFirstChild.childNodes[0].childNodes.length;
                   for (i=0; i<totalImages; i++) {
                           imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
                   }
                   trace(imageFileName[i]); // Should give you the file name for each image in the trace window
           }
    }


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •