Copy link to clipboard
Copied
hi guys
i have 3 classes in the library (external classes) and 1 document class called Main
in HERO class character should move but it not
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
and here are the codes
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);
}
}
}
i hope you guys can help because i tried to move the hero but i couldn.t the whole problem from the HERO class (i guess)
thank you
What do you not understand when I say "I don't see the HERO class in any code you show, and if there is no instance of it on the stage, then you have no HERO object to move." ?
Unfortunately, regardless of you saying there is an instance, nothing you show for code supports that at all, so there is nothing else I can comment on about it.
Copy link to clipboard
Copied
The HERO class by itself function properly. I do not see where you import that class into the Main or any other class however. If it is an object on the stage, is the class file located somewhere that your main file can locate it?
Copy link to clipboard
Copied
"If it is an object on the stage"
no nothing in the main stage its empty but when the program starting it will MAINMAP1 object because of this command
public function Main() {
addChild(mainmap1);
"is the class file located somewhere that your main file can locate it?"
in mainmap1 class there are hero class and tree class inside it
thank you
Copy link to clipboard
Copied
I don't see the HERO class in any code you show, and if there is no instance of it on the stage, then you have no HERO object to move. Nothing is creating one and there is none to begin with otherwise.
What you might try to help you understand and get this working is to create a new fla file and create a movieclip on the stage and assign it the class name HERO via its linkage. Then, with the HERO class file in the same folder as that fla, run the fla. YOu should see the HERO object moving with your keyboard controls.
Then, remove that object from the stage and in the first frame use... var hero:HERO = new HERO(); addChild(hero); ... and you should see the same result of being able to move a dynamically created instance of HERO around with the keyboard.
Then see how to work this into the other file you are wroking on.
Copy link to clipboard
Copied
sorry
i realy cant understand you
but here what i know in the mainmap1 there is instance of HERO class and it called hero
Copy link to clipboard
Copied
What do you not understand when I say "I don't see the HERO class in any code you show, and if there is no instance of it on the stage, then you have no HERO object to move." ?
Unfortunately, regardless of you saying there is an instance, nothing you show for code supports that at all, so there is nothing else I can comment on about it.
Copy link to clipboard
Copied
no sorry,
here what am trying to say, the hero class the (blue) up in my first comment and i gave an instance of it to the mainmap1 class so the program can access to it when it
run
is that what you want to know?
Copy link to clipboard
Copied
can i upload the fla file and you can take a little look to it if you dont mind dr.murphy?
because i realy tried to understand you but i couldn.t
thank you for your time