Flex 学习笔记 Move类的使用

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

今天使用了flex 将以前所做的一个flash 网站重写尝试写一次,真的感叹lex 的开发速度是如此快,功能如此强大,

使用move 类进行一些简单配置。

制作流程:

定义一个移动的函数

 
   private function MoveToPostion(obj:Move,button:Object,xfrom:Number,xto:Number):void
   {
      obj=new Move();
      obj.target=button;
      obj.xFrom=xfrom;
      obj.xTo=xto;
      obj.play();
     
   }
   

这里我们就可以实现对一个对象进行移动。

用法:

 private var move1:Move;
   

    MoveToPostion(move1,Company,712,50);

当中id就是Company,就是按钮,这里只是用了一个按钮做一些简单的测试而已。


 <mx:Button x="712" y="19" height="515" width="30" id="Company"   click="ButtonMove(event)" styleName="mybutton1"/>

源代码:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  3.     <mx:Style>
  4.         .mybutton1
  5.         {
  6.          upSkin:Embed("../image/button1.png");
  7.          overSkin:Embed("../image/button1.png");
  8.          downSkin:Embed("../image/button1.png")
  9.         }
  10.         
  11.         .mybutton2
  12.         {
  13.          upSkin:Embed("../image/button2.png");
  14.          overSkin:Embed("../image/button2.png");
  15.          downSkin:Embed("../image/button2.png")
  16.         }
  17.         
  18.         
  19.         .mybutton3
  20.         {
  21.          upSkin:Embed("../image/button3.png");
  22.          overSkin:Embed("../image/button3.png");
  23.          downSkin:Embed("../image/button3.png")
  24.         }
  25.         
  26.         .mybutton4
  27.         {
  28.          upSkin:Embed("../image/button4.png");
  29.          overSkin:Embed("../image/button4.png");
  30.          downSkin:Embed("../image/button4.png")
  31.         }
  32.         .mybutton5
  33.         {
  34.          upSkin:Embed("../image/button5.png");
  35.          overSkin:Embed("../image/button5.png");
  36.          downSkin:Embed("../image/button5.png")
  37.         }
  38.         
  39.         
  40.         
  41.     </mx:Style>
  42.     
  43.     <mx:Script>
  44.         <![CDATA[
  45.             import mx.effects.Move;
  46.             import mx.effects.easing.*;
  47.             import flash.events.*;
  48.             import mx.events.*;
  49.             import mx.effects.Tween;
  50.             import mx.events.*;
  51.              
  52.             private var position:Array=[]; 
  53.              private var move1:Move;
  54.             private var move2:Move;
  55.             private var move3:Move;
  56.             private var move4:Move;
  57.             private var move5:Move;
  58.             
  59.             private var Ismove1:Boolean=true;
  60.             private var Ismove2:Boolean=true;
  61.             private var Ismove3:Boolean=true;
  62.             private var Ismove4:Boolean=true;
  63.             private var Ismove5:Boolean=true;
  64.              
  65.             private function init():void
  66.             {
  67.             
  68.             
  69.             
  70.             }
  71.             
  72.             private function ButtonMove(event:MouseEvent):void
  73.             {
  74.              if(Button(event.currentTarget)==Company)
  75.               {
  76.                  
  77.                 if(Ismove1)
  78.                 {
  79.                  MoveToPostion(move1,Company,712,50);
  80.                  Ismove1=false;                 
  81.                
  82.                 }
  83.                 
  84.                 else if(!Ismove1 && Ismove2)
  85.                {
  86.                   trace("dd");
  87.                  MoveToPostion(move1,Company,50,712);
  88.                  Ismove1=true;
  89.                }
  90.                //单条运行
  91.                
  92.                //向后走
  93.              if(!Ismove2 && Ismove3 )
  94.              {
  95.                trace("2");
  96.                 MoveToPostion(move1,Company,50,712);
  97.                 Ismove1=true;
  98.                             
  99.                 MoveToPostion(move2,Production,80,741);
  100.                 Ismove2=true;
  101.                          
  102.              }
  103.              
  104.               if(!Ismove3 && Ismove4 )
  105.              { trace("3");
  106.              
  107.                 MoveToPostion(move1,Company,50,712);
  108.                             Ismove1=true;                   
  109.                 MoveToPostion(move2,Production,80,741); 
  110.                             Ismove2=true;    
  111.                 MoveToPostion(move3,Information,110,768);
  112.                
  113.                 Ismove3=true;
  114.                      
  115.              }
  116.              
  117.              if(!Ismove4 && Ismove5)
  118.              {trace("4");
  119.               MoveToPostion(move4,Business,140,796);
  120.                  Ismove4=true;
  121.                  
  122.                  
  123.                 MoveToPostion(move3,Information,110,768);
  124.                 Ismove3=true;
  125.                 
  126.                  MoveToPostion(move2,Production,80,741);
  127.                 Ismove2=true;
  128.                 
  129.                 MoveToPostion(move1,Company,50,712);
  130.                 Ismove1=true;
  131.                                      
  132.              }
  133.              if(!Ismove5)
  134.              {trace("5");
  135.                  MoveToPostion(move1,Company,50,712);
  136.                 Ismove1=true;
  137.                             
  138.                 MoveToPostion(move2,Production,80,741);
  139.                 Ismove2=true;
  140.                 
  141.                 MoveToPostion(move3,Information,110,768);
  142.                 Ismove3=true;
  143.                      
  144.                  MoveToPostion(move4,Business,140,796);
  145.                  Ismove4=true;
  146.                 
  147.                  MoveToPostion(move5,Contact,170,825);
  148.                 Ismove5=true;
  149.              
  150.              }
  151.              
  152.                                 
  153.               }
  154.               
  155.               
  156.               
  157.               
  158.               //按钮2运动
  159.               if(Button(event.currentTarget)==Production)
  160.               {
  161.                 if(Ismove2 && !Ismove1 && Ismove3)
  162.                 {
  163.                 trace("aaa");
  164.                  MoveToPostion(move2,Production,714,80);
  165.                  Ismove2=false;
  166.                 
  167.                 }
  168.                 
  169.                 else  if( !Ismove2 && Ismove3 && !Ismove1)
  170.                {
  171.                  trace("bbbb");
  172.                  MoveToPostion(move2,Production,80,741);
  173.                  Ismove2=true;
  174.                
  175.                }
  176.                 
  177.                                 
  178.                 if(Ismove2 && Ismove1)
  179.                {
  180.                   MoveToPostion(move2,Production,741,80);
  181.                   Ismove2=false;
  182.                 
  183.                   MoveToPostion(move1,Company,712,50);
  184.                   Ismove1=false;
  185.                 
  186.                 
  187.                }
  188.                
  189.                if(!Ismove3 && Ismove4 && !Ismove2)
  190.                {
  191.                
  192.                   trace("33");
  193.                 MoveToPostion(move3,Information,110,768);
  194.                 Ismove3=true;
  195.                 
  196.                  MoveToPostion(move2,Production,80,741);
  197.                 Ismove2=true;
  198.                
  199.                
  200.                
  201.                }
  202.                
  203.                if(!Ismove4 && Ismove5 && !Ismove2 )
  204.                {
  205.                 trace("44");
  206.                   MoveToPostion(move2,Production,80,741);
  207.                 Ismove2=true;
  208.                 
  209.                 MoveToPostion(move3,Information,110,768);
  210.                 Ismove3=true;
  211.                      
  212.                  MoveToPostion(move4,Business,140,796);
  213.                  Ismove4=true;
  214.                
  215.                
  216.                
  217.                }
  218.                
  219.                if(!Ismove5 && !Ismove2)
  220.                {
  221.                trace("55");
  222.                 MoveToPostion(move2,Production,80,741);
  223.                 Ismove2=true;
  224.                 
  225.                 MoveToPostion(move3,Information,110,768);
  226.                 Ismove3=true;
  227.                      
  228.                  MoveToPostion(move4,Business,140,796);
  229.                  Ismove4=true;
  230.                 
  231.                  MoveToPostion(move5,Contact,170,825);
  232.                   Ismove5=true;
  233.                
  234.                }
  235.                
  236.                       
  237.              
  238.               }
  239.               
  240.               //第三个按钮在这里
  241.                 if(Button(event.currentTarget)==Information)
  242.               {
  243.                  if(Ismove3  && !Ismove2)
  244.                { 
  245.                 trace("1111");
  246.                 MoveToPostion(move3,Information,768,110);
  247.                 Ismove3=false;
  248.                } 
  249.                else  if(!Ismove3 && Ismove4)
  250.                 {
  251.                     trace("333");
  252.                   MoveToPostion(move3,Information,110,768);
  253.                   Ismove3=true;
  254.                 
  255.                 }
  256.                 
  257.              
  258.                if(Ismove3 && Ismove1 )
  259.                {
  260.                 
  261.                 MoveToPostion(move3,Information,768,110);
  262.                 Ismove3=false;
  263.                               
  264.                 MoveToPostion(move2,Production,741,80);             
  265.                 Ismove2=false;
  266.                 
  267.                 MoveToPostion(move1,Company,712,50);         
  268.                 Ismove1=false;
  269.                     
  270.                
  271.                }
  272.                
  273.                
  274.                 if(Ismove3 && Ismove2 && ! Ismove1)
  275.                {
  276.                  
  277.                 MoveToPostion(move3,Information,768,110);
  278.                 Ismove3=false;
  279.                
  280.                 MoveToPostion(move2,Production,741,80);             
  281.                 Ismove2=false;
  282.                            
  283.                }
  284.                            
  285.                 if( !Ismove4 && Ismove5)
  286.                {
  287.                 
  288.                  MoveToPostion(move3,Information,110,768);
  289.                  Ismove3=true;
  290.                
  291.                  MoveToPostion(move4,Business,140,796);
  292.                  Ismove4=true;
  293.                 
  294.                
  295.                }
  296.                
  297.                if(!Ismove5)
  298.                {
  299.                  trace("你dianl 我");
  300.                  MoveToPostion(move3,Information,110,768);
  301.                  Ismove3=true;
  302.                
  303.                  MoveToPostion(move4,Business,140,796);
  304.                  Ismove4=true;
  305.                
  306.                 MoveToPostion(move5,Contact,170,825);
  307.                 Ismove5=true;
  308.                
  309.                }
  310.                        
  311.               }
  312.               
  313.              
  314.              //第四个按钮 
  315.                 if(Button(event.currentTarget)==Business)
  316.               {
  317.                  if(Ismove4 && !Ismove3 )
  318.                 {
  319.                    trace("disi");
  320.                  MoveToPostion(move4,Business,796,140);     
  321.                  Ismove4=false;
  322.                 
  323.                 }
  324.                 else if(!Ismove4 && !Ismove3 && Ismove5)
  325.                 {
  326.                     trace("444444");
  327.                  MoveToPostion(move4,Business,140,796);     
  328.                  Ismove4=true;      
  329.                 }
  330.                         
  331.                             
  332.                if(Ismove4 && Ismove1)
  333.               {  
  334.                 
  335.                 MoveToPostion(move4,Business,796,140);      
  336.                 Ismove4=false;
  337.               
  338.                 MoveToPostion(move1,Company,712,50);         
  339.                 Ismove1=false;
  340.                               
  341.                 MoveToPostion(move3,Information,768,110);
  342.                 Ismove3=false;
  343.                
  344.                 MoveToPostion(move2,Production,741,80);             
  345.                 Ismove2=false;
  346.                       
  347.               }
  348.               
  349.                if(Ismove4  && !Ismove1 && Ismove2)
  350.               
  351.               {
  352.                  MoveToPostion(move4,Business,796,140);     
  353.                  Ismove4=false;
  354.                               
  355.                 MoveToPostion(move3,Information,768,110);
  356.                 Ismove3=false;
  357.                
  358.                 MoveToPostion(move2,Production,741,80);             
  359.                 Ismove2=false;
  360.               
  361.               }
  362.               
  363.               if(Ismove4 && !Ismove2 && Ismove3)
  364.               {
  365.                MoveToPostion(move4,Business,796,140);       
  366.                  Ismove4=false;
  367.                               
  368.                 MoveToPostion(move3,Information,768,110);
  369.                 Ismove3=false;
  370.               
  371.               }
  372.               
  373.               
  374.              if(!Ismove5 &&!Ismove4)
  375.              {
  376.              
  377.               MoveToPostion(move4,Business,140,796);        
  378.              Ismove4=true;
  379.              
  380.               MoveToPostion(move5,Contact,170,825);
  381.               Ismove5=true;
  382.              }
  383.              
  384.              
  385.              
  386.               }
  387.               
  388.               //第五个按钮
  389.               
  390.                 if(Button(event.currentTarget)==Contact)
  391.               {
  392.                 if(Ismove1)
  393.                {     
  394.                  trace("1");
  395.                  MoveToPostion(move5,Contact,825,170);
  396.                  Ismove5=false;
  397.              
  398.                  MoveToPostion(move4,Business,796,140);     
  399.                  Ismove4=false;
  400.              
  401.                  MoveToPostion(move3,Information,768,110);
  402.                  Ismove3=false;
  403.                               
  404.                  MoveToPostion(move2,Production,741,80);                
  405.                  Ismove2=false;
  406.                 
  407.                  MoveToPostion(move1,Company,712,50);        
  408.                  Ismove1=false;
  409.                      
  410.              
  411.               }
  412.               else if(!Ismove5)
  413.               {
  414.                trace("6");
  415.               
  416.                 MoveToPostion(move5,Contact,170,825);
  417.                 Ismove5=true;
  418.               
  419.               }
  420.               else 
  421.                    if(Ismove5 && !Ismove4 )
  422.                {trace("5");
  423.                   MoveToPostion(move5,Contact,825,170);
  424.                  Ismove5=false;
  425.                 
  426.                }
  427.               
  428.               
  429.              
  430.                if(Ismove5 && !Ismove1 && Ismove2)
  431.                {
  432.                trace("2");
  433.                  MoveToPostion(move5,Contact,825,170);
  434.                  Ismove5=false;
  435.              
  436.                  MoveToPostion(move4,Business,796,140);     
  437.                  Ismove4=false;
  438.              
  439.                  MoveToPostion(move3,Information,768,110);
  440.                 Ismove3=false;
  441.                               
  442.                  MoveToPostion(move2,Production,741,80);                
  443.                  Ismove2=false;
  444.                
  445.                
  446.                          
  447.                }
  448.                
  449.                if(Ismove5 && !Ismove2 && Ismove3 )
  450.                {
  451.                 trace("3");
  452.                    MoveToPostion(move5,Contact,825,170);
  453.                   Ismove5=false;
  454.              
  455.                   MoveToPostion(move4,Business,796,140);        
  456.                   Ismove4=false;
  457.              
  458.                   MoveToPostion(move3,Information,768,110);
  459.                  Ismove3=false;
  460.                }
  461.                
  462.                if(Ismove5 && !Ismove3 && Ismove4)
  463.                {
  464.                trace("4");
  465.                 MoveToPostion(move5,Contact,825,170);
  466.                  Ismove5=false;
  467.              
  468.                MoveToPostion(move4,Business,796,140);       
  469.                  Ismove4=false;
  470.                }
  471.                
  472.      
  473.               
  474.             }
  475.              
  476.             }
  477.             
  478.             
  479.             
  480.             
  481.             private function MoveToPostion(obj:Move,button:Object,xfrom:Number,xto:Number):void
  482.             {
  483.                obj=new Move();
  484.                obj.target=button;
  485.                obj.xFrom=xfrom;
  486.                obj.xTo=xto;
  487.                obj.play();
  488.                     
  489.             }
  490.              
  491.              
  492.              
  493.         ]]>
  494.     </mx:Script>
  495.     <!--!<mx:Parallel id="para" target="{Company}">
  496.     <mx:Move xFrom="711"     xTo="50" easingFunction="{Exponential.easeOut}"/>  
  497.     </mx:Parallel>-->
  498.      
  499.     <mx:Button x="712" y="19" height="515" width="30" id="Company"   click="ButtonMove(event)" styleName="mybutton1"/>
  500.     <mx:Button x="741" y="19" height="515" width="30" id="Production" click="ButtonMove(event)" styleName="mybutton2"/>
  501.     <mx:Button x="768" y="19" height="515" width="30" id="Information" click="ButtonMove(event)" styleName="mybutton3"/>
  502.     <mx:Button x="796" y="19" height="515" width="30" id="Business" click="ButtonMove(event)" styleName="mybutton4"/>
  503.     <mx:Button x="825" y="19" height="515" width="30" id="Contact" click="ButtonMove(event)" styleName="mybutton5"/>
  504.     
  505.     
  506. </mx:Application>

使用move 类可以实现一些简单的效果,原理其实就是缓冲公式一个使用而已。

这里效果还可以加上其他效果,如模糊,缩放等。

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/truhfcg/article/details/83919913