hi guys
i have 3 classes in the library (external classes) and 1 document class called Main
the program running but with 2 warrnings
| C:\Users\win7\Desktop\first rpg\HERO.as, Line 49 | Warning: 1090: Migration issue: The onKeyDown event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'keyDown', callback_handler). |
| C:\Users\win7\Desktop\first rpg\HERO.as, Line 76 | Warning: 1090: Migration issue: The onKeyUp event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0. You must first register this handler for the event using addEventListener ( 'keyUp', callback_handler). |
so i cant move the hero because these warrnings then i tried to do what warrning said
in HERO class i did this
addEventListener('keyDown',callback_handler);
addEventListener('keyUp',callback_handler);
then i get 2 errors without warnnings
here are the classes code (the external classes ) in the lib
MAINMAP1 class
package
{
import flash.system.System;
import flash.system.fscommand;
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
public class MAINMAP1 extends MovieClip {
var vx:int = 0
var vy:int = 0
public function MAINMAP1(){
addEventListener(Event.ADDED_TO_STAGE, onAdded)
}
public function onAdded (event:Event):void {
}
}
}
tree1 class
package{
import flash.system.System;
import flash.system.fscommand;
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
public class tree1 extends MovieClip{
public function tree1 (){
addEventListener(Event.ADDED_TO_STAGE, onAdded)
}
public function onAdded (){
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(event:Event){
{
}
}
}
}
HERO class
package{
import flash.system.System;
import flash.system.fscommand;
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
public class HERO extends MovieClip{
private var vx:int = 0;
private var vy:int = 0;
public function HERO (){
addEventListener(Event.ADDED_TO_STAGE, onAdded)
}
public function onAdded (event:Event):void {
gotoAndStop(3)
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
}
public function onEnterFrame(event:Event){
x += vx
y += vy
}
public function onKeyDown(event:KeyboardEvent){
if (event.keyCode == Keyboard.LEFT){
gotoAndStop(2)
vx = -5
}
if (event.keyCode == Keyboard.RIGHT){
gotoAndStop(1)
vx = 5
}
if (event.keyCode == Keyboard.DOWN){
vy = +5
gotoAndStop(6)
}
if (event.keyCode == Keyboard.UP){
vy = -5
}
}
public function onKeyUp(event:KeyboardEvent){
if (event.keyCode == Keyboard.LEFT ||event.keyCode == Keyboard.RIGHT ){
vx= 0;
}
if (event.keyCode == Keyboard.UP ||event.keyCode == Keyboard.DOWN ){
vy= 0;
}
}
}
}
THE DOCUMENT CLASS (Main)
package {
import flash.system.System;
import flash.system.fscommand;
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Stage;
public class Main extends MovieClip {
var mainmap1:MAINMAP1 = new MAINMAP1;
public function Main() {
addChild(mainmap1);
}
}
}
done
the program run but i cant move the hero because of these warrnings
thank you
Migration issues pertain to using AS1/AS2-like coding in an AS3 file. In your case, you have a few function names that are AS2 built-in functions and that is why the migration warnings are occuring. If you want to avoid the warnings change the names of your functions... namely: onEnterFrame , onKeyDown, and onKeyUp
ahh thanks i changed it in hero class like this
onEnterFramehero
onKeyDownhero
onKeyUphero
the warrnings gone but still i cant move hero
here more details there is document class called (Main) and then class in lib called (MAINMAP1) inside this class 2 classes the tree and hero
in the last game the code work well and its the same excpet ( there is only 1 document class) and nothing else but here 4 classes
thank you for your time
North America
Europe, Middle East and Africa
Asia Pacific