【问题标题】:Making image move in FLEX/AS flash使图像在 FLEX/AS 闪存中移动
【发布时间】:2011-08-11 18:37:08
【问题描述】:

在下面的代码中,点击水果图片如何使水果图片以适当的效果落入盒子图像中(即应该显示水果图像落入盒子图像中)..

          <?xml version="1.0" encoding="utf-8"?>
           <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

           <mx:Script>
              <![CDATA[
              import mx.controls.Button;
              import mx.controls.Alert;

              public function clickhandler(event:Event):void
              {

              }
                 ]]>

           </mx:Script>

               <mx:Canvas id="myCanvas" 
                 height="800" width="800"
                 borderStyle="solid" 
                 backgroundColor="#A9C0E7">

                 <mx:Image 
                   height="50" width="50" 
                   x="100" y="10"
                   source="@Embed(source='fruits.jpg')" 
                   click="clickhandler(event)" />

                 <mx:Image 
                   height="200" width="200" 
                   x="300" y="350" 
                   source="@Embed(source='box.jpg')" />
                </mx:Canvas>


           <!--<mx:TextInput x="231" y="175" id="txtLogin"/>-->



           </mx:Application>

【问题讨论】:

    标签: actionscript-3 flash mxml mxmlc


    【解决方案1】:

    您可以使用以下代码:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application layout="absolute" xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:Script>
        <![CDATA[
            public function clickhandler(event:Event):void
            {
                fruitAnimation.play();
            }
        ]]>
        </mx:Script>
    
        <mx:Move id="fruitAnimation" target="{fruitImage}" xTo="375" yTo="450" />
    
        <mx:Canvas backgroundColor="#A9C0E7" borderStyle="solid" height="800" id="myCanvas" width="800">
            <mx:Image click="clickhandler(event)" height="50" id="fruitImage" source="@Embed(source='fruits.jpg')"
                width="50" x="100" y="10" />
            <mx:Image height="200" source="@Embed(source='box.jpg')" width="200" x="300" y="350" />
        </mx:Canvas>
    </mx:Application>
    

    如果要添加抛物线运动,可以使用以下代码:

    <?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
            {
                fruitAnimation.play();
            }
        ]]>
        </mx:Script>
    
        <mx:Parallel id="fruitAnimation" target="{fruitImage}">
            <mx:AnimateProperty property="x" toValue="375" easingFunction="{Quadratic.easeOut}" />
            <mx:AnimateProperty property="y" toValue="450" />
        </mx:Parallel>
    
        <mx:Canvas backgroundColor="#A9C0E7" borderStyle="solid" height="800" id="myCanvas" width="800">
            <mx:Image click="clickhandler(event)" height="50" id="fruitImage" source="@Embed(source='fruits.jpg')"
                width="50" x="100" y="10" />
            <mx:Image height="200" source="@Embed(source='box.jpg')" width="200" x="300" y="350" />
        </mx:Canvas>
    </mx:Application>
    

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      http://www.greensock.com/tweenlite/下载 tweenLite 库

      那么你可以使用下面的代码:

      public function clickhandler(e:Event):void
      {
          TweenLite.to(e.target, 0.5, {x: 300, y: 350});
      }
      

      【讨论】:

      • 我正在使用开源 flex SDK,我应该将它解压缩到哪里。这是我的目录结构../opt/flex-sdk,其中的目录是ant bin flex-sdk-description.xml lib license-mpl.htm samples templates asdoc flex_sdk_4.1.0.16076_mpl.zip frameworks license-adobesdk-fr.htm readme.htm SDK license.pdf
      • 你有你的代码源文件的地方,你应该在那里解压缩它:) (例如,如果你有 main.mxml,你应该在那里解压缩它,然后你应该看到一个新的名为 com/greensock 的目录 :) )
      猜你喜欢
      • 2013-04-15
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      • 2011-02-13
      • 2010-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多