A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: load movie clips from library and position them randomly

  1. #1
    Junior Member
    Join Date
    May 2003
    Posts
    24

    load movie clips from library and position them randomly

    Hi,

    I have 13 movie clips in library and I would like to load them and position them one after the other (horizontaly) but in random order.

    Should I load them in some kind of array and then randomly switch places in that array and then position them like array[1], array[2], array[3]... ?

    thank you

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Yes.

  3. #3
    Junior Member
    Join Date
    Sep 2004
    Posts
    18
    please if you can tell me some more if it is not too much of your time. I have experience in AS 2, but never did anything with arrays.

    thank you, I'll try something myself and post it here, if you can give me some hints I would be gratefull

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    stop();
    // array of the export linkage identifiers of the movie clips in the library
    var icons = ["icon1", "icon2", "icon3", "icon4", "icon5", "icon6", "icon7", "icon8"];
    // amount of spacing between movie clips
    var i_spacing = 10;
    // left most position of first movie clip
    var i_startX = 30;
    
    // loop through the icons array
    for (var i in icons) {
    	// get a random location in the array
    	var r = Math.floor(Math.random()*icons.length);
    	// temp store identifier
    	var tmp = icons[i];
    	// put random identifier into location
    	icons[i] = icons[r];
    	// swap first identifier into random location
    	icons[r] = tmp;
    }
    
    // loop through the randomised icons array 
    for (var j = 0; j<icons.length; j++) {
    	// attach the movie clip from the library
    	var myicon = attachMovie(icons[j], icons[j], this.getNextHighestDepth());
    	// set attached clip's x position
    	myicon._x = i_startX;
    	// set attached clip's y position
    	myicon._y = 30;
    	// update x position for next loop interation
    	i_startX += myicon._width+i_spacing;
    }

  5. #5
    Junior Member
    Join Date
    May 2003
    Posts
    24
    thank you so much... what I'm trying to do next is that you can click one item and get it selected (stored in some variable) and changed alpha. This is what I have for now but it's not working:

    Code:
    stop();
    
    // array of the export linkage identifiers of the movie clips in the library
    var icons = ["selection_part_1","selection_part_2","selection_part_3","selection_part_4","selection_part_4","selection_part_5","selection_part_7b","selection_part_8","selection_part_9","selection_part_10","selection_part_11"];
    // amount of spacing between movie clips
    var i_spacing = 20;
    // left most position of first movie clip
    var i_startX = 20;
    
    // loop through the icons array
    for (var i in icons) {
    	// get a random location in the array
    	var r = Math.floor(Math.random()*icons.length);
    	// temp store identifier
    	var tmp = icons[i];
    	// put random identifier into location
    	icons[i] = icons[r];
    	// swap first identifier into random location
    	icons[r] = tmp;
    }
    
    // loop through the randomised icons array 
    for (var j = 0; j<icons.length; j++) {
    	// attach the movie clip from the library
    	var myicon:MovieClip = attachMovie(icons[j], icons[j], this.getNextHighestDepth());
    	// set attached clip's x position
    	myicon._x = i_startX;
    	// set attached clip's y position
    	myicon._y = 5;
    	// update x position for next loop interation
    	i_startX += myicon._width+i_spacing;
    	myicon._alpha = 70;
    	myicon.useHandCursor = true;
    	myicon.onRollOver = function () {
        	this._alpha = 100;
    	}
    	myicon.onRollOut = function () {
        	this._alpha = 70;
    	}
    
    	var myiconArray:Array = Array();
    	myiconArray[j] = myicon;
    	trace(myiconArray[j]);
    	myiconArray[j].onPress = function () {
    		if (myiconArray[j] == this._name){
    			this._alpha = 100;
    			continue;
    		}
    		
    	}
    }
    any toughts?

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Not sure I understand...is this closer to what you need?
    Code:
    stop();
    
    // array of the export linkage identifiers of the movie clips in the library
    var icons = ["selection_part_1","selection_part_2","selection_part_3","selection_part_4","selection_part_4","selection_part_5","selection_part_7b","selection_part_8","selection_part_9","selection_part_10","selection_part_11"];
    var i_spacing = 20;
    var i_startX = 20;
    
    for (var i in icons) {
    	var r = Math.floor(Math.random()*icons.length);
    	var tmp = icons[i];
    	icons[i] = icons[r];
    	icons[r] = tmp;
    }
    var btns = new Array()
    for (var j = 0; j<icons.length; j++) {
    	var myicon:MovieClip = attachMovie(icons[j], "b"+j, this.getNextHighestDepth());
    	myicon._x = i_startX;
    	myicon._y = 5;
    	i_startX += myicon._width+i_spacing;
    	myicon._alpha = 70;
    	myicon.useHandCursor = true;
    	myicon.onRollOver = doOver;
    	myicon.onRollOut = doOut;
    	myicon.onPress = doPress;
    	btns.push(myicon)
    }
    var currentSelect;
    
    function doOver() {
    	this._alpha = 100;
    }
    function doOut() {
    	if (currentSelect != this) {
    		this._alpha = 70;
    	}
    }
    function doPress() {
    	for (i in btns) {
    		btns[i]._alpha = 70;
    	}
    	if (currentSelect != this) {
    		this._alpha = 100;
    		currentSelect = this;
    	}else{
    		currentSelect = null;
    	}
    }

  7. #7
    Junior Member
    Join Date
    May 2003
    Posts
    24
    thank you dawsonk, that's what I needed

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center