move the object left and right
hi < how all? hope fine...
iam trying make more spells hero , spell fireball
and want move right when hero on right left when hero on left
i tried code when press w should move 10 or 20 px should stop
but idont step "then should stop" because of error fireball does,t move
as want
typeerror: error #1010: term undefined , has no properties.
at hero/onenterframe()
here code
hero class
package {
import flash.display.movieclip;
import flash.events.keyboardevent;
import flash.ui.keyboard;
import flash.events.event;
import flash.sensors.accelerometer;
import flash.media.sound;
import flash.media.soundchannel;
public class hero extends movieclip {
var nightjungle:nightjungle = new nightjungle
var electricalshield:electricalshield=new electricalshield ;
var speed:int=3;
var fireballindex:array = new array
var dir:int;
var electricity:electricity = new electricity;
var soundchannel:soundchannel = new soundchannel
var firespeed:int = 50
var i:int
public function hero() {
addeventlistener(event.added_to_stage,onaddedtostage);
}
public function onaddedtostage(event:event):void {
addeventlistener(event.enter_frame,onenterframe );
stage.addeventlistener(keyboardevent.key_down,onkeydown);
stage.addeventlistener(keyboardevent.key_up,onkeyup);
soundchannel = nightjungle.play(1,1000)
gotoandstop(4);
}
public function onenterframe(event:event):void {
x +=dir*speed;
if(fireballindex[i].stage){
fireballindex[i].x += 1
}
}
public function onkeydown(event:keyboardevent):void {
if (event.keycode==keyboard.right) {
gotoandstop(2);
dir=1;
speed = 10
if (electricalshield.stage)
addchild(electricalshield)
}
if (event.keycode==keyboard.left) {
gotoandstop(1);
dir=-1;
speed = 10
if (electricalshield.stage)
addchild(electricalshield)
}
if (event.keycode==keyboard.up) {
gotoandstop(1);
y=10;
}
if (event.keycode==keyboard.q) {
speed=30;
addchild(electricalshield);
soundchannel = electricity.play()
}
if (event.keycode == keyboard.w) {
fireballindex.push(new fireball())
addchild(fireballindex[i])
fireballindex[i].width = 50
fireballindex[i].x += firespeed * dir
i++
trace(i)
}
if (event.keycode == keyboard.e) {
movieclip(parent).aa.x = x +100
}
}
public function onkeyup(event:keyboardevent):void {
if (event.keycode==keyboard.q) {
if (electricalshield.stage) {
removechild(electricalshield);
if (soundchannel != null)
speed=0;
soundchannel = electricity.play(1,1)
}
}
if (event.keycode==keyboard.w) {
}
if (event.keycode==keyboard.left) {
speed = 0
gotoandstop(3);
if (electricalshield.stage)
addchild(electricalshield)
} else if (event.keycode == keyboard.right) {
speed =0
gotoandstop(4);
if (electricalshield.stage)
addchild(electricalshield)
}
}
}
}
thank you
use trace command find out object in oneneterframe function causing error...
public function onenterframe(event:event):void {
trace(x, dir, speed, i, fireballindex[i], fireballindex[i].stage);
x +=dir*speed;
if(fireballindex[i].stage){
fireballindex[i].x += 1
}
}
More discussions in ActionScript 3
adobe
Comments
Post a Comment