----------------------------------------------------------------------------------------------------------
bullet.as
-----------------------------------------------------------------------------------------------------------
package {import flash.display.Sprite;
import flash.events.Event;
public class bullet extends Sprite {
private var sw:Number;
private var sh:Number;
private const _SPEED:int=10;
private const _OFFSTAGE:int=-10;
public function bullet():void {
addEventListener(Event.ADDED_TO_STAGE,onadd);
}
private function onadd(e:Event):void {
sw=stage.stageWidth;
sh=stage.stageHeight;
addEventListener(Event.ENTER_FRAME,loop);
}
private function loop(e:Event):void {
if (y<_OFFSTAGE) {
removeEventListener(Event.ENTER_FRAME,loop);
parent.removeChild(this);
}
y-=_SPEED;
}
public function removeListeners():void {
removeEventListener(Event.ENTER_FRAME,loop);
}
}
}
----------------------------------------------------------------------------------------------------------
TimeLine
-----------------------------------------------------------------------------------------------------------
var sfx_gun:Sound = new sfx();
var sp:MovieClip = new ship();
var bulletholder:Sprite = new Sprite();
addChild(bulletholder);
addChild(sp);
addEventListener(Event.ENTER_FRAME,onenter);
stage.addEventListener(MouseEvent.CLICK,onclick);
function onenter(e:Event):void {
sp.x-=(sp.x-mouseX)*.1;
sp.y-=(sp.y-350)*.2;
}
function onclick(e:Event) {
sfx_gun.play();
sp.y=365;
var bl:Sprite = new bullet();
bl.y=sp.y;
bl.x=sp.x;
bulletholder.addChild(bl);
}
--------------------------------------------------------------------------------------------------------------
READ MORE:
http://www.on-design.de/tutor/FlsExpl/AS3/hitTest/index.htm
-------------------------------------------------------------------------------------------------------------
READ MORE:
http://www.on-design.de/tutor/FlsExpl/AS3/hitTest/index.htm
-------------------------------------------------------------------------------------------------------------
EmoticonEmoticon