-
[RESOLVED] [ AS3 ] Player class (OOP)
Hi, I'm a rookie at Actionsript 3. I'm trying to make a player class with a parameter to create an object related to the class name that was passed by this parameter in the constructor method.
PHP Code:
package
{
import flash.display.MovieClip;
public class Player extends MovieClip
{
private var _player:MovieClip;
public function Player(n)
{
_player = new n();
createPlayer();
}
private function createPlayer():void
{
stage.addChild(_player);
}
}
}
PHP Code:
package
{
import flash.display.MovieClip;
import Player;
public class Main extends MovieClip
{
private var _player:MovieClip;
public function Main()
{
_player = new Player(LiuKang);
}
}
}
-
I'm fairly certain you have to pass a class name as a parameter. It's been a while for me to do much with as3. This should probably be it for you: https://stackoverflow.com/questions/...ate-from-class
-
Senior Member
I'm trying to make a player class with a parameter to create an object related to the class name that was passed by this parameter in the constructor method
I see. You did not ask any questions, and the code should work. Maybe you'd see some warnings
PHP Code:
package
{
import flash.display.MovieClip;
public class Player extends MovieClip
{
private var _player:MovieClip;
public function Player(n:Class) // here
{
_player = (new n()) as MovieClip; // and here
createPlayer(); // this might fail because stage is null - dont call it
// you might do this.addEventListener(Event.ADDED_TO_STAGE, createPlayer);
}
private function createPlayer(e:Event = null):void // then it has to have arguments
{
stage.addChild(_player);
}
}
}
Last edited by realMakc; 08-07-2017 at 05:36 PM.
-
You did not ask any questions
Forgive me, I just forgot.
Maybe you'd see some warnings
I was getting the error 1009. I'll test your code, thanks!
-
-
Darn, realMakc the link I provided basically supplied the same info. Have fun Mr. Crazy!
-
Originally Posted by swak
Darn, realMakc the link I provided basically supplied the same info.
I don't know if I tested it wrong, but the link code you gave me doesn't work.
Haha OK, thanks
-
Originally Posted by CrazY.
I don't know if I tested it wrong, but the link code you gave me doesn't work.
It takes a bit of sorting but the first post was someone giving their code that had problems with answers below. The one with the green checkmark was the one you should look at for the answer. I could have provided the answer but I figured that an example would help in other ways better.
-
is resolved. i sure they know how use so web site.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|