Copy link to clipboard
Copied
I need to make a bouncing ball animation for a uni assignment, and then have 3 radio buttons that you can click to make the ball change to either blue, red or green.
I have put three Radio Button components on the stage with the instance names of "red" "blue" and "green", and the instance name of the object I want to change is "ball".
I know to transform an object's colour you use this code:
var myColorTransform = new ColorTransform ();
myColorTransform.color = 0xFF0000;
ball.transform.colorTransform = myColorTransform;
but how do I "attach" this to the radio button?
or you could use:
red.addEventListener(MouseEvent.CLICK,ColorTransformF);
green.addEventListener(MouseEvent.CLICK,ColorTransformF);
blue.addEventListener(MouseEvent.CLICK,ColorTransformF);
function ColorTransformF(e:MouseEvent): void{
var myColorTransform = ball.transform.colorTransform;
if(e.currentTarget.name=='red'){
myColorTransform.color = 0xFF0000;
} else if(e.currentTarget.name=='green'){
myColorTransform.color=0x00ff00;
} else {
myColorTransform.color=0x0000ff;
}
ball.transform.colorTransform = myCol
...Copy link to clipboard
Copied
create radio button listens and add your transforms to the listener functions.
Copy link to clipboard
Copied
Is this okay?
red.addEventListener(MouseEvent.CLICK,ColorTransform);
function ColorTransform(e:MouseEvent): void{
}
What do I put in for the rest?
Copy link to clipboard
Copied
red.addEventListener(MouseEvent.CLICK,ColorTransformF);
function ColorTransformF(e:MouseEvent): void{
var myColorTransform = ball.transform.colorTransform
myColorTransform.color = 0xFF0000;
ball.transform.colorTransform = myColorTransform;
}
Copy link to clipboard
Copied
It gives me an output error:
TypeError: Error #1010: A term is undefined and has no properties.
at Untitled_fla::MainTimeline/ColorTransformF()
Copy link to clipboard
Copied
click file>publish settings>and tick 'permit debugging'. retest.
the line number with the undefined term will be in the error message allowing you to pinpoint the problem in your code. if that doesn't make the solution to the problem obvious to you, copy and paste the line number mentioned in the error message and copy/paste the error message.
Copy link to clipboard
Copied
It doesn't give me any Compiler Errors, just the Output error that I posted above.
Copy link to clipboard
Copied
tick 'permit debugging' and retest (though if the only code you have is the code i suggested there are only two possiblities: you either don't have anything named red or you don't have anything named ball when the code executes).
Copy link to clipboard
Copied
I did click on it, here is the Output code:
TypeError: Error #1010: A term is undefined and has no properties.
at SphereRadioButtons_fla::MainTimeline/ColorTransformF()[SphereRadioButtons_fla.MainTimeline::frame1:5]
I did have problems with finding the objects and right instance names so I restarted, the ball is now Sphere, and the radio button is still red, so I changed the instance name for the code:
red.addEventListener(MouseEvent.CLICK,ColorTransformF);
function ColorTransformF(e:MouseEvent):void{
var myColorTransform = Sphere.transform.colorTransform
myColorTransform.color = 0xFF0000;
Sphere.transfrom.colorTransform = myColorTransform;
}
Copy link to clipboard
Copied
that error message indicates your error is on frame 1, line 5.
if that's:
Sphere.transfrom.colorTransform = myColorTransform;
it means Sphere is undefined. actionscript is case-sensitive so sphere is not the same as Sphere.
Copy link to clipboard
Copied
Okay, I redid the whole thing again and it finally works, but now when I do the same for the other two buttons it says duplicate function definition, and error "5000: The class 'fl.core.ComponentShim' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type." and "The class 'fl.controls.RadioButton' must sublass 'flash.display.MovieClip' since it is linked to a library symbol of that type."
Copy link to clipboard
Copied
you have a component problem (eg, you're using a non-as3 component or you edited one or more radio button symbols in your library) that's going to be difficult to pinpoint via a forum.
you should start over and create a new as3 fla, drag a radio button from the component panel to the stage and give it an instance name (in the properties panel) of red. create a new movieclip, add it to the stage and assign an instance name of ball. open the actionscript panel and copy and paste the code i suggested.
Copy link to clipboard
Copied
Yeah that makes the red one work perfectly fine, but I need two more buttons that changes that ball to green and blue aswell, and when I use that code it says duplicate function.
Copy link to clipboard
Copied
your functions need different names.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Copy link to clipboard
Copied
or you could use:
red.addEventListener(MouseEvent.CLICK,ColorTransformF);
green.addEventListener(MouseEvent.CLICK,ColorTransformF);
blue.addEventListener(MouseEvent.CLICK,ColorTransformF);
function ColorTransformF(e:MouseEvent): void{
var myColorTransform = ball.transform.colorTransform;
if(e.currentTarget.name=='red'){
myColorTransform.color = 0xFF0000;
} else if(e.currentTarget.name=='green'){
myColorTransform.color=0x00ff00;
} else {
myColorTransform.color=0x0000ff;
}
ball.transform.colorTransform = myColorTransform;
}
Copy link to clipboard
Copied
Thanks man, it works perfectly now
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now