获取在行动脚本/ MXML IDS脚本、行动、IDS、MXML

2023-09-09 21:56:35 作者:风骚似水似花似你妈

木卫一以下code如何让所有的IDS水果图像onlcick的button.Is还有像类属性和获得的ID,然后......

 < XML版本=1.0编码=UTF-8&GT?;
  < MX:应用程序布局=绝对的xmlns:MX =htt​​p://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 =htt​​p://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:用途>
 

但它似乎是你可以用列表转发解决你的任务更优雅的方式。只是不知道您的要求。

让 Android 融入国产平台应用生态体系的解决方案 TD IDS

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.