Using targetCurrent -- I am able to get the name of the MovieClip a user clicks on.
On function toggleClick there is a trace 开发者_如何学Gostatement 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"};
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()];
精彩评论