0

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.

1 Answer 1

1

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');

}
Sign up to request clarification or add additional context in comments.

1 Comment

ah! duh. cheers... overthinking it i suppose. works just dandy :) thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.