Flex 构建器层次结构输出中的 Action script3 跟踪
我正在使用 Flex builder 4.5,我的问题是这个代码不起作用,当我使用 Trace(event.target) 时,我在控制台中得到以下结果,
deleteme.ApplicationSkin2._ApplicationSkin_Group1.contentGroup.VGroup5.button1
如果我替换“if”语句中的这一长行,代码就可以工作。 (deleteme是项目名称)。你不认为它应该只说button1而不是所有层次结构的长线,如果是这样的话我们如何缩短它?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
initialize="handleClick(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function init():void{
button2.addEventListener(MouseEvent.CLICK, handleClick);
}
private function handleClick(event:Event):void{
trace(event.target);
if(event.target == "button1"){
button1.label = "Button 1 clicked";
}else if(event.target == "button2"){
button2.label = "Button 2 clicked";
}
}
]]>
</fx:Script>
<s:VGroup width="100%">
<s:Button id="button1" label="Button 1" click="handleClick(event)"/>
<s:Button id="button2" label="Button 2" />
</s:VGroup>
</s:Application>
预先感谢,
(我尝试使用 sdk 4.1 还是相同的答案)
i am using Flex builder 4.5 and my problem is this that this code doos not work, when i used trace(event.target) i get following in result in console,
deleteme.ApplicationSkin2._ApplicationSkin_Group1.contentGroup.VGroup5.button1
And if i replace this long line in 'if' statement code works.(deleteme is the project name). Dont you think it should only say button1 instead of this all long line with all hierarchy , if that is the case then how we can shortend it?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
initialize="handleClick(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function init():void{
button2.addEventListener(MouseEvent.CLICK, handleClick);
}
private function handleClick(event:Event):void{
trace(event.target);
if(event.target == "button1"){
button1.label = "Button 1 clicked";
}else if(event.target == "button2"){
button2.label = "Button 2 clicked";
}
}
]]>
</fx:Script>
<s:VGroup width="100%">
<s:Button id="button1" label="Button 1" click="handleClick(event)"/>
<s:Button id="button2" label="Button 2" />
</s:VGroup>
</s:Application>
thanks in advance,
(i tried with sdk 4.1 still same answer)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请改用以下代码:
将视觉对象与字符串进行比较是没有意义的。将物体与物体本身进行比较。
Use the following code instead:
It has no sense to compare visual objects with strings. Compare objects with objects themselves.