0

I have a button in flash and I want to generate an automatic color for my square.

I have this function

private function btnClick(event:MouseEvent):void
        {

        var mycolor :ColorTransform = new ColorTransform();
        mycolor.color = (Math.random() * 0xFFFFFF);
        parcare.transform.colorTranform = mycolor;
        }

I get this error

: 4 Error: Access of undefined property parcare. parcare.transform.colorTranform = mycolor;

Do you know how can I solve it? Thank you!

2 Answers2

0

To create a random hex color is:

'#'+Math.floor(Math.random()*16777215).toString(16);

And As A function is:

function random() {
    var a = '#'+Math.floor(Math.random()*16777215).toString(16);
    return a;
}
0

this is a scope problem, the random colour generating is fine

the onClick function is outside of the scope of the rest of your class. You need to find a way for the function to know what the variable parcare is.

There is no easy way of fixing it for you without seeing more code.

look a at this question for more info To pass a parameter to event listener in AS3 the simple way... does it exist?

Community
  • 1
  • 1
Daniel
  • 34,125
  • 17
  • 102
  • 150