For the “starship” document Created with actionscript 3.0 in Adobe Flash CS4

cabbagetreatmentSoftware and s/w Development

Jul 4, 2012 (5 years and 2 months ago)

305 views

//By Parker Diard. 12/24/2009. For the “starship” document Created with actionscript 3.0 in Adobe Flash CS4

//Code that’s in the keyframe:
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);
}
//Code that’s in an external actionscript file:
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);

}
}
}