如何从闪存中的对象(关联数组)中获取值,并将该值重新分配给新变量?
我的闪光灯舞台上有多个切换按钮。这些切换按钮是影片剪辑。如果用户单击其中一个 MovieClip,我希望能够找到一种方法来遍历下面的对象 - 根据用户单击的内容获取适当的值 - 并将该值存储在名为 var powerData 的新值中然后将其传递给函数来执行计算。
var houseArray:Object = {lightA:"1",
lightB:"1",
lightC: "1"
lightD: "1"
lightE: "1"
comp: "2"
tv: "3"
stove: "4"
laundry: "5"};
例如: 如果用户单击“Comp”MovieClip 那么——> var 电源数据 = 2; (因为在 houseArray:Object--> comp: "2" 中)
I have multiple toggle buttons on my flash stage. These toggle buttons are MovieClips. If a user clicks on one of the MovieClips, I want to be able to find a way to go through the Object below--get the appropriate value based on what the User clicked--and store that value in a new value called var powerData which will then be passed to a function to perform calculations.
var houseArray:Object = {lightA:"1",
lightB:"1",
lightC: "1"
lightD: "1"
lightE: "1"
comp: "2"
tv: "3"
stove: "4"
laundry: "5"};
For example:
If the user clicked on "Comp" MovieClip
then--> var powerData = 2; (because in houseArray:Object--> comp: "2")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要根据 houseArray 对象的属性来命名您的 MovieClips 实例。在您的示例中, Comp 实例应命名为 "comp" ,电视应命名为 "tv" 等等...
我认为您有充分的理由将 houseArray 中的属性命名为字符串...
You will need to name your MovieClips instances after the properties of the houseArray object. In your example, the Comp instance should be named "comp" , the TV "tv" and so on...
I assume you have good reasons to have the properties in houseArray as Strings...