Copy link to clipboard
Copied
If someone can help me out with this problem I would greatly apprciate it. In AS3 I have 1 ball being exported out in actionscript in layer 1 from the library then gets placed on stage when the .swf publishes. here is the code:
The coin movieclip represents the "ball" and its the same movieclip over and over again. (works great no errors)
----code------------
// generates new Coin - Coin is the name of MovieClip in Library
// remember to export for Actionscript
var c1:Coin = new Coin();
var chosenNumsIndex1:uint = chosenNumsIndex;
trace("chosenNumsIndex1 outside " +chosenNumsIndex1);
// coin is placed at appropriate x and y coords
c1.x = kNum[chosenNums[chosenNumsIndex]].x;
c1.y = kNum[chosenNums[chosenNumsIndex]].y;
// addChild tells main timeline to display coin once it's generated.
this.addChild(c1);
What I want to achieve is to have 8+ random movieclips created and linked to the "coin" so when it gets exported it is not the same ball all the time so this is what I have for that:
var ballsArray:Array = [ball00,ball01,ball02,ball03,ball04,ball05,ball06,ball07,ball08];------- movieclips in the library
Question: how do I get the coin to read this array randomly so it doesnt go to "coin movieclip"and just play the one ball i would like it go play the ball of arrays?
thank you very much in advance
Copy link to clipboard
Copied
assign the class names to an array:
var ballClassA:Array=["Ball00","Ball01",...];
function createBallF():void{
var C:Class=Class(getDefinitionByName(ballClassA[Math.floor(ballClassA.length*Math.random())]));
var c:MovieClip=new C();
addChild(c);
}
Copy link to clipboard
Copied
kglad, I had pasted the code above given me errors..
Scene 1, Layer 'actions', Frame 1, Line 186 | 1084: Syntax error: expecting rightparen before ngth. |
Scene 1, Layer 'actions', Frame 1, Line 186 | 1084: Syntax error: expecting rightbracket before rightparen. |
updated & then more errors... But where whould I paste it to replace the "coin"
// generates new Coin - Coin is the name of MovieClip in Library
// remember to export for Actionscript
var c1:Coin = new Coin();
var chosenNumsIndex1:uint = chosenNumsIndex;
trace("chosenNumsIndex1 outside " +chosenNumsIndex1);
// coin is placed at appropriate x and y coords
c1.x = kNum[chosenNums[chosenNumsIndex]].x;
c1.y = kNum[chosenNums[chosenNumsIndex]].y;
// addChild tells main timeline to display coin once it's generated.
this.addChild(c1);
trace(chosenNums[chosenNumsIndex])
Copy link to clipboard
Copied
this forum distorts code. remove errant white space in the code.
what you called coin i call c in the code.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now