Reputation: 213
I have an empty array collecting a hex value thats randomly selected from another array within a function. i am trying to pull the hex value from the array that gets filled and pass it to another function to randomly change the color value of a particle system...
private var ca:Array = new Array();
private var rc:String = ca; // pseudo...this is the string that needs to get passed
public function addCursor(cursor:Cursor):void {
var cc:Array = new Array("0xFFFF33", "0xFFFFFF", "0x79DCF4", "0xFF3333", "0xFFCC33", "0x99CC33");
var rcc:String = cc[Math.floor(Math.random() * (cc.length))];
ca.push(rcc); //
trace(rcc + ' 1st array');
trace(ca + ' 2nd array');
trace(rc + ' string to pass');
// unrelated stuff happens down here...
the 1st and 2nd arrays both trace the same hex value, but i cant find the right way to capture that string...ive tried several different methods that all return 'null' ...which makes me think maybe the value is leaving the array before i try to snag it?
i removed ca.pop()
which is called in a later function, just to see if rc
would still return a null and it does.
Upvotes: 0
Views: 178
Reputation: 3851
rcc is a string, not an array.
So
trace(rcc + ' chosen hex as a string');
But I don't see why you need an array (ca) just to hold a single string.
This would work:
private var rc:String;
private var cc:Array = new Array("0xFFFF33", "0xFFFFFF", "0x79DCF4", "0xFF3333", "0xFFCC33", "0x99CC33");
public function addCursor(cursor:Cursor):void {
rc = cc[Math.floor(Math.random() * (cc.length))];
trace(rc + ' the chosen hex');
}
Upvotes: 1