PDA

View Full Version : [AS3] Use a checkbox to display/ hide an image


tpmgx6
03-12-2009, 07:34 PM
Howdy. I'm building a project that will display different line graphs of different interest rates for 8 credit cards. I'm creating the line graphs in Illustrator and then exporting them as jpgs.

I will then import just the lines of the line graphs into Flash. Then the user will be able to click on each type of credit card and see the line graph for it. I want them to be able to see as many as they want on the stage. This is helpful because the lines sometimes are really close, so just viewing two or three at time is useful.

My question is how do I make the checkbox component display an image when it is checked and hide the image when it isn't? Is it a question of loading the image (movieclip) using labels, similar to the way the combobox works?

Any help would be great.

Thanks ya'll!

palmjack
03-12-2009, 08:07 PM
checkBox.addEventListener(Event.CHANGE, toggleMc, false, 0, true);

function toggleMc(e:Event):void
{
checkBox.selected ? mc.visible = true : mc.visible = false;
}

mc - instance name of your movie clip
checkBox - instance name of your check box component

tpmgx6
03-13-2009, 08:05 PM
Thanks palmjack. The code works great overall. There's just one thing.

Whenever I run the movie initally, the movieclips are visible on the stage. Then when I click the checkbox, nothing happens. Then when I uncheck the box the movieclips go away, as they should.

My question is how do I have the movieclips not visible at the start of the movie?

Thanks you!

palmjack
03-13-2009, 10:10 PM
You can set the visibility of your mc to false
mc.visible = false;

checkBox.addEventListener(Event.CHANGE, toggleMc, false, 0, true);

function toggleMc(e:Event):void
{
checkBox.selected ? mc.visible = true : mc.visible = false;
}

graphicguru_india
04-21-2009, 09:56 AM
You can set the visibility of your mc to false
mc.visible = false;

checkBox.addEventListener(Event.CHANGE, toggleMc, false, 0, true);

function toggleMc(e:Event):void
{
checkBox.selected ? mc.visible = true : mc.visible = false;
}

how to change this in AS2, this is in AS3.

zavior
10-28-2009, 02:26 PM
This is great!!!
How could I use this code to load/unload external swf's upon selecting/deselecting the checkbox??
Thanx!!