--------------------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW CODE
https://www.youtube.com/watch?v=CTc2vu7Adnk
https://www.youtube.com/watch?v=jQFxPuLntyg
DOWNLOAD SOURCE FILE
http://bit.ly/175k6jZ
--------------------------------------------------------------------------------------------------------------------
//MAKE 3 MOVIE SYMBOLS,GIVE INSTANCE NAME "MOVIE1","MOVIE2","MOVIE3"
var MovieArray:Array = new Array(MOVIE1,MOVIE2,MOVIE3);
for(var i:int = 0; i < MovieArray.length; i++){
var RandomNumber:Number = Math.floor(Math.random()* MovieArray.length)
var MoviePosX:Number = MovieArray[RandomNumber].x;
var MoviePosY:Number = MovieArray[RandomNumber].y;
MovieArray[RandomNumber].x = MovieArray[i].x;
MovieArray[RandomNumber].y = MovieArray[i].y;
MovieArray[i].x = MoviePosX
MovieArray[i].y = MoviePosY
}
------------------------------------------------------------------------------------------------------------------------
OR USE THIS CODE
https://www.youtube.com/watch?v=Ww-DCd5TfyM
http://textuploader.com/6c9n
------------------------------------------------------------------------------------------------------------------------
//MAKE 3 MOVIE SYMBOLS,GIVE INSTANCE NAME "MOVIE1","MOVIE2","MOVIE3"
var MovieArray:Array = new Array(MOVIE1,MOVIE2,MOVIE3);
for(var i:int = 0; i < 3; i++){
var RandomNumber:Number = Math.floor(Math.random() * (3 - i) );
var MoviePosX:Number = MovieArray[RandomNumber].x;
var MoviePosY:Number = MovieArray[RandomNumber].y;
MovieArray[RandomNumber].x = MovieArray[i].x;
MovieArray[RandomNumber].y = MovieArray[i].y;
MovieArray[i].x = MoviePosX
MovieArray[i].y = MoviePosY
}
-------------------------------------------------------------------------------------------------------------
HOW TO LOAD A RANDOM MOVIE CLIP FROM LIBRARY TO AN EMPTY MOVIECLIPS
NEED TO UNDER STAND HOW EMPTY MOVIE CLIP LOAD CIRCLE MOVIE CLIP
IN THIS WAY YOU GIVE NAME CIRCLE MOVIE CLIP CLASS NAME McClass
HERE RED BOX INSTNACE NAME emptyMC
var myMovieClip:McClass = new McClass();
emptyMC.addChild(myMovieClip);
------------------------------------------------------------------------------------------------------------------
http://www.flashwonderland.com/load-library-movieclip/load-mc-3.html
Sometimes you may have more than one MovieClips in the Flash Library. This Flash tutorial shows how to load a random MovieClip from Library to an Empty MovieClip on the Stage with Flash ActionScript.
--------------------------------------------------------------------------------------------------------------
/*
Preparation: Create Linkage for the MovieClip
Preparation: Create Linkage for the MovieClip
STEP 1: Prepare MovieClips
You already prepared three MovieClips in the library
In this example, the name of the MovieClips are:
- Tree
- Sun
- FootBall
You already prepared three MovieClips in the library
In this example, the name of the MovieClips are:
- Tree
- Sun
- FootBall
STEP 2: Create Linkage
Select the movieclip from the library window
Select "Linkage..." from the pop up window
The Linkage Properties window appear
Check the "Export for ActionScript"
Enter Name in the Class field
In this example, we used "Tree", "Sun" and "FootBall" for the class name
Select the movieclip from the library window
Select "Linkage..." from the pop up window
The Linkage Properties window appear
Check the "Export for ActionScript"
Enter Name in the Class field
In this example, we used "Tree", "Sun" and "FootBall" for the class name
Preparation: Create an empty MovieClip
1. Select "Insert" from the menu.
2. Select "New Symbol" from the drop down menu
3. The "Create New Symbol" window pop up.
4. Enter "emptyMC" in the Name field. Select MovieClip.
5. Select "Scene"
6. Drag the "emptyMC" to a desired position on the stage (e.g. 150, 210)
7. Give a new instance name "emptyMC_mc" to this empty MovieClip
*/
2. Select "New Symbol" from the drop down menu
3. The "Create New Symbol" window pop up.
4. Enter "emptyMC" in the Name field. Select MovieClip.
5. Select "Scene"
6. Drag the "emptyMC" to a desired position on the stage (e.g. 150, 210)
7. Give a new instance name "emptyMC_mc" to this empty MovieClip
*/
//Create an empty Array with the name movieArray
var movieArray:Array = new Array();
var movieArray:Array = new Array();
//Put the MovieClips into the Array
//The size of this Array is now 3
movieArray = ["Tree", "Sun", "FootBall"];
//The size of this Array is now 3
movieArray = ["Tree", "Sun", "FootBall"];
// Declare variable to use later
var myMovieClip:MovieClip;
var myMovieClip:MovieClip;
if ((movieArray[Math.floor(Math.random() * 3)]) == "Tree") {
myMovieClip = new Tree();
output_txt.text = "The Tree MovieClip was added!";
} else if ((movieArray[Math.floor(Math.random() * 3)]) == "Sun") {
myMovieClip = new Sun();
output_txt.text = "The Sun MovieClip was added!";
} else if ((movieArray[Math.floor(Math.random() * 3)]) == "FootBall") {
myMovieClip = new FootBall();
output_txt.text = "The FootBall MovieClip was added!";
} else { // In case the random number is 1
output_txt.text = "The FootBall MovieClip was added!";
}
// Add the new MovieClip to the empty MovieClip
// so that we can see it.
emptyMC_mc.addChild(myMovieClip);
// so that we can see it.
emptyMC_mc.addChild(myMovieClip);
// Set the location if required
//emptyMC_mc.x = 250;
//emptyMC_mc.y = 210;
//emptyMC_mc.x = 250;
//emptyMC_mc.y = 210;
-------------------------------------------------------------------------------------------------------------
OR USE THIS CODE
http://stackoverflow.com/questions/10405961/as3-addchild-based-on-array-value
var selection:String = typeArray[ int(Math.random() * typeArray.length) ];
-------------------------------------------------------------------------------------------------------------// MAKE 3 MOVIE CLIPS AND SET CLASS NAMES : ball, wall, fall
//http://stackoverflow.com/questions/10405961/as3-addchild-based-on-array-value
var myArray = ["ball", "wall", "fall"];
function createRandom(typeArray:Array):*{
var selection:String = typeArray[Math.floor(Math.random()* 3)];
var Type:Class = getDefinitionByName(selection)as Class;
return new Type();
}
var instance:DisplayObject = createRandom(myArray);
addChild(instance);
EmoticonEmoticon