views:

31

answers:

1

Using targetCurrent -- I am able to get the name of the MovieClip a user clicks on.

On function toggleClick there is a trace statement that says:

trace("movieClip Instance Name = " + e.currentTarget);

OUTPUT Window:

movieClip Instance Name = [object Comp]

Based on what a user clicks on -- there will be a value associated to the MovieClip.

On the flash stage there are multiple toggle buttons: User can toggle the MovieClips ON or OFF. On the stage there are MovieClips of the following: a computer, light bulb, and TV. The user can toggle the objects ON or OFF.

If the user clicks on the 'Computer' MovieClip...

I want to be able to loop through houseArray--and when the loop finds comp in the array-- in a variable called var powerData -- it will store the power value of comp. (I am unsure how to write that process in AS3.) In houseArray comp = "2" --so...

var powerData:int = 2;

                    var houseArray:Object = {lightA:"1", 
                                            lightB:"1", 
                                            lightC: "1"
                                            lightD: "1"
                                            lightE: "1"
                                            comp: "2"
                                            tv: "3"
                                            stove: "4"
                                            laundry: "5"};
+1  A: 

Since houseArray is an Object, not an Array, you don't need to loop through it to get the value. What you do need to do is get "comp" when you click on the "Comp" MovieClip. There are numerous ways to do this. If your MovieClip's instance name is "Comp" then you can just do this:

var powerData:int = houseArray[e.currentTarget.name.toLowerCase()];
sberry2A
I put:var powerData:int = houseArray[e.currentTarget.name.toLowerCase()];inside the function toggleClick.Also inside the toggleClick function I trace powerData:trace(powerData);when I click the "Comp" MovieClip...in the OUTPUT window:0var powerData should have the value of 2.
jc70
@sberry2A thank you, I was able to fix the problem I was having. Something in my code was causing it not to work properly. Thank you for showing me how to write the code to have the MovieClip correspond to the right value I needed.
jc70