1. 程式人生 > >Flex 學習筆記 Move類的使用

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.         &nbs