顯示具有 flash-actionscript 標籤的文章。 顯示所有文章
顯示具有 flash-actionscript 標籤的文章。 顯示所有文章

2013年11月10日 星期日

actionscript - array

helpful:
http://livedocs.adobe.com/flash/9.0_tw/ActionScriptLangRefV3/Array.html



var myArray:Array = new Array("Flash", "ActionScript", "Republic of Code");
trace(myArray);
trace(myArray[0]);


//add elementmyArray[3] = "Tutorial";

//remove from 2nd and 1 item
myArray.splice(2,1);

//remove the last item
myArray.pop();

//add one item at the last
myArray.push("39");










2013年11月3日 星期日

actionscript keyboard event

function reportKeyDown(event:KeyboardEvent):void 
{ 
    trace("Key Pressed: " + String.fromCharCode(event.charCode) +         " (character code: " + event.charCode + ")"); 
} 
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);

2012年12月29日 星期六

2012.12.29-actionscript drag drop moiveclip 拉 move mouse

package  {
   
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
   
   
    public class moon extends MovieClip {
       
       
        public function moon() {
            buttonMode=true;
            this.addEventListener(MouseEvent.MOUSE_DOWN, ondown)  ;
            this.addEventListener(MouseEvent.MOUSE_UP, onUp)  ;
           
        }           
            protected function ondown(event:MouseEvent):void
            {    
                startDrag();
            }
           
            protected function onUp(evt:MouseEvent):void
        {
            evt.target.stopDrag();
        }
    }
   
}

2011.12.28-actionscript collision 碰撞


var  b1:ball1=new ball();
var  b2:ball1=new ball();

if(b1.hitTestObject(b2)){
 trace("hit");
}

2012年12月28日 星期五

2011.12.28-actionscript sound play volume changed

    import flash.media.Sound;




var BG:Sound = new BGMusic();
var myChannel:SoundChannel = new SoundChannel();
var myTransform = new SoundTransform();



myChannel =BG.play();

myTransform.volume = 0.1;
myChannel.soundTransform = myTransform;

2012年11月8日 星期四

2011.11.8-actionscript dispatch custom listener

互相呼應的2個CLASS一定要自定義而且有連接外部AS文件



==========================================================
CLASS1:

package  {
 import flash.events.Event;
 import flash.display.MovieClip;
 import flash.events.MouseEvent;

 public class ball extends MovieClip  {

  public function ball() {
   this.addEventListener(MouseEvent.CLICK, onClick);
  
  }


  private function onClick(event:MouseEvent):void
  {
   //trace("asd");
   dispatchEvent(new Event("clickball", true));
  
  }

 
 }

}

==========================================================
CLASS2:

package  {

 import flash.events.Event;
 import flash.display.MovieClip;
 import flash.events.MouseEvent;
   


 public class gameplan extends MovieClip {

  public function gameplan() {
  
   stage.addEventListener("clickball", onCatEvent);
  
  }
  
  
   function onCatEvent(event:Event)
   {
    trace("asd");
   }

 }

}


==========================================================




















2011.11.8-actionscript text field format size font


 import flash.text.TextField;
 import flash.text.TextFormat;


   var txt:TextField = new TextField();
   var txtF:TextFormat = new TextFormat();


   txtF.font = "Arial";
   txtF.size = 30;
   txtF.color = 0x000000;
  
   txt.width=130;
   txt.x = 50;
   txt.y = 25;
   txt.text = "Score:"+score;
   txt.setTextFormat(txtF);

   addChild(txt);

2012年11月5日 星期一

2012.11.5-actionscript- ball moving movieclip rotate

    import flash.events.TimerEvent;
    import flash.utils.Timer;


var timer:Timer = new Timer(10,0);


timer.start();
timer.addEventListener(TimerEvent.TIMER, updateTime);



function updateTime(e:TimerEvent):void{

  if(!excess()){

   ball.x+=dx;
   ball.y+=dy;
   ball.rotation=angle;

  }
}

2012.11.5-actionscript-array movieclip click tagget




for(var i:int = 0; i{

var ballArr:Array = [];
var tempBall:ball;


 tempBall = new ball();
 ballArr[i] = tempBall;

 tempBall.addEventListener(MouseEvent.CLICK, click_handler);


   addChild(ballArr[i]);
}




function click_handler(e:MouseEvent) {

 if(!(e.target).isDead()){
    dosomething();
 }


}

2012.11.5-actionscript-array movieclip add child


var ballArr:Array = [];
var tempBall:ball;
var numOfBall:Number=10;


for(var i:int = 0; i{

 tempBall = new ball();

 ballArr[i] = tempBall;

 tempBall.x = 0;
 tempBall.y = 0;

 tempBall.rotation=30;

 tempBall.addEventListener(MouseEvent.CLICK, click_handler);

   addChild(ballArr[i]);
}

2012.11.5-actionscript-timer

    import flash.events.TimerEvent;
    import flash.utils.Timer;


var timer:Timer = new Timer(10,0);

timer.start();
timer.stop();
timer.addEventListener(TimerEvent.TIMER, updateTime);

function updateTime(e:TimerEvent):void{

}

2011.11.5-actionscript-movieclip click event



import flash.display.MovieClip;

ball.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void {
trace("asd!");
}

2012.11.5-actionscript-BUTTON CLICK , ENABLE , VISIBLE


BUT1.addEventListener (MouseEvent.CLICK, gamestart);


function gamestart ( event:MouseEvent):void

{
    startbut1.enabled=false;
    startbut1.visible=false;
    playPlan1.gotoAndPlay("playPlan");

}