获取在行动脚本/ MXML IDS [英] Get ids in Action script/mxml
本文介绍了获取在行动脚本/ MXML IDS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
木卫一以下code如何让所有的IDS水果图像onlcick的button.Is还有像类属性和获得的ID,然后......
< XML版本=1.0编码=UTF-8&GT?;
< MX:应用程序布局=绝对的xmlns:MX =http://www.adobe.com/2006/mxml>
< MX:脚本>
<![CDATA [
进口mx.effects.easing.Quadratic;
公共职能clickHandler事件(事件:事件):无效
{
//如何获得的唯一fruits.jpg图像中的所有IDS
}
]]≥
< / MX:脚本>
< MX:移动ID =fruitAnimation1目标={fruitImage}x要=100YTO =10/>
< MX:帆布的backgroundColor =#A9C0E7的borderStyle =坚实的高度=800ID =myCanvasWIDTH =800>
< MX:图像高度=50ID =fruitImage来源=@嵌入(来源='fruits.jpg')WIDTH =50X =100Y =10/>
< MX:图像高度=50ID =fruitImage1来源=@嵌入(来源='fruits.jpg')WIDTH =50X =150Y =10/>
< MX:图像高度=50ID =fruitImage2来源=@嵌入(来源='fruits.jpg')WIDTH =50X =200Y =10/>
< MX:图像高度=50ID =fruitImage3来源=@嵌入(来源='fruits.jpg')WIDTH =50X =250Y =10/>
< MX:图像高度=200来源=@嵌入(来源='box.jpg')WIDTH =200X =300Y =350/>
< / MX:帆布>
< MX:按钮标签=点击点击=clickHandler事件(事件),X =100Y =316/>
< / MX:用途>
解决方案
尝试使用以下命令:
< XML版本=1.0编码=UTF-8&GT?;
< MX:应用程序布局=绝对的xmlns:MX =http://www.adobe.com/2006/mxml>
< MX:脚本>
<![CDATA [
[可绑定(__ NoChangeEvent__)
[嵌入(来源=fruits.jpg)
私人VAR fruitImageClass:类;
公共职能clickHandler事件(事件:事件):无效
{
VAR numChildren的:INT = myCanvas.numChildren;
对于(VAR我:= 0; I< numChildren的;我++)
{
VAR孩子:的DisplayObject = myCanvas.getChildAt(我);
如果(孩子图片)
{
VAR图片:图片=图像(子);
如果(image.source == fruitImageClass)
跟踪(image.id);
}
}
}
]]≥
< / MX:脚本>
< MX:移动ID =fruitAnimation1目标={fruitImage}x要=100YTO =10/>
< MX:帆布的backgroundColor =#A9C0E7的borderStyle =坚实的高度=800ID =myCanvasWIDTH =800>
< MX:图像高度=50ID =fruitImage来源={fruitImageClass}WIDTH =50X =100Y =10/>
&所述;米×:图像高度=50的id =fruitImage1源={fruitImageClass}宽度=50×=150Y =10/>
&所述;米×:图像高度=50的id =fruitImage2源={fruitImageClass}宽度=50×=200Y =10/>
&所述;米×:图像高度=50的id =fruitImage3源={fruitImageClass}宽度=50×=250Y =10/>
< MX:图像高度=200来源=@嵌入(来源='box.jpg')WIDTH =200X =300Y =350/>
< / MX:帆布>
< MX:按钮点击=clickHandler事件(事件)的标签=ClidkX =100Y =316/>
< / MX:用途>
但它似乎是你可以用列表
或转发
解决你的任务更优雅的方式。只是不知道您的要求。
Io the following code how to get all the ids for fruits image onlcick of the button.Is there like a class attribute and get the ids then....
<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.effects.easing.Quadratic;
public function clickhandler(event:Event):void
{
//How to get all the ids of fruits.jpg image only
}
]]>
</mx:Script>
<mx:Move id="fruitAnimation1" target="{fruitImage}" xTo="100" yTo="10" />
<mx:Canvas backgroundColor="#A9C0E7" borderStyle="solid" height="800" id="myCanvas" width="800">
<mx:Image height="50" id="fruitImage" source="@Embed(source='fruits.jpg')" width="50" x="100" y="10" />
<mx:Image height="50" id="fruitImage1" source="@Embed(source='fruits.jpg')" width="50" x="150" y="10" />
<mx:Image height="50" id="fruitImage2" source="@Embed(source='fruits.jpg')" width="50" x="200" y="10" />
<mx:Image height="50" id="fruitImage3" source="@Embed(source='fruits.jpg')" width="50" x="250" y="10" />
<mx:Image height="200" source="@Embed(source='box.jpg')" width="200" x="300" y="350" />
</mx:Canvas>
<mx:Button label="Click" click="clickhandler(event)" x="100" y="316"/>
</mx:Application>
解决方案
Try to use the following:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
[Bindable("__NoChangeEvent__")]
[Embed(source="fruits.jpg")]
private var fruitImageClass:Class;
public function clickhandler(event:Event):void
{
var numChildren:int = myCanvas.numChildren;
for (var i:int = 0; i < numChildren; i++)
{
var child:DisplayObject = myCanvas.getChildAt(i);
if (child is Image)
{
var image:Image = Image(child);
if (image.source == fruitImageClass)
trace(image.id);
}
}
}
]]>
</mx:Script>
<mx:Move id="fruitAnimation1" target="{fruitImage}" xTo="100" yTo="10" />
<mx:Canvas backgroundColor="#A9C0E7" borderStyle="solid" height="800" id="myCanvas" width="800">
<mx:Image height="50" id="fruitImage" source="{fruitImageClass}" width="50" x="100" y="10" />
<mx:Image height="50" id="fruitImage1" source="{fruitImageClass}" width="50" x="150" y="10" />
<mx:Image height="50" id="fruitImage2" source="{fruitImageClass}" width="50" x="200" y="10" />
<mx:Image height="50" id="fruitImage3" source="{fruitImageClass}" width="50" x="250" y="10" />
<mx:Image height="200" source="@Embed(source='box.jpg')" width="200" x="300" y="350" />
</mx:Canvas>
<mx:Button click="clickhandler(event)" label="Clidk" x="100" y="316" />
</mx:Application>
But it seems to be you can solve your task more elegant way using List
or Repeater
. Just have no idea about your requirements.
这篇关于获取在行动脚本/ MXML IDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文