I am currently trying to get acclimated to FlashDevelop, but am having trouble moving an entity, despite following tutorials very closely.
public class Main extends Engine
{
private var gameWorld:MyWorld;
public function Main()
{
super(800, 600, 60, false);
gameWorld = new MyWorld;
}
override public function init():void
{
FP.world = gameWorld;
trace("FlashPunk has started successfully!");
}
}
public class MyWorld extends World
{
private var gameEntity:MyEntity;
public function MyWorld()
{
gameEntity = new MyEntity();
add(gameEntity);
}
override public function update():void
{
//trace("MyEntity updates");
}
}
public class MyEntity extends Entity
{
[Embed(source = "dragon.png")] private const PLAYER:Class;
public function MyEntity()
{
name = "player";
graphic = new Image(PLAYER);
}
override public function update():void
{
x += 10;
y += 5;
//if (Input.check(Key.LEFT)) { x -= 5; }
//if (Input.check(Key.RIGHT)) { x += 5; }
//if (Input.check(Key.UP)) { y -= 5; }
//if (Input.check(Key.DOWN)) { y += 5; }
}
override public function added():void
{
trace("Entity added");
}
}
It is supposed to move across the screen, but does not for some reason. Any thoughts?
Related
I'm making a game in which I need my hero to shoot, but I can't realize why the bullets aren't moving. They appear on the stage but they stay in the place they appear and don't move. I can't find my mistake. Thanks!!
So this is the class that has to make appear and move the bullets when I press Space.
public class Nivel_1
{
public var mc:MainChar = new MainChar();
public var Ene:Enemigo = new Enemigo();
public var bullet:Bullet = new Bullet();
public var Back:MC_Nivel_1 = new MC_Nivel_1()
public var Spawn_Boss:Boolean =false;
public var boss:Boss = new Boss();
public static var balaVector:Vector.<Bullet> = new Vector.<Bullet>();
public var disparo:Boolean = false;
public function Nivel_1()
{
}
public function Iniciar():void
{
Main.escenario.addEventListener(Event.ENTER_FRAME, Update);
Main.escenario.addChild(Back);
Ene.Init(600,630);
mc.Init(100,150);
Main.escenario.addEventListener(KeyboardEvent.KEY_UP, OnKeyUpLv1);
Main.escenario.addEventListener(KeyboardEvent.KEY_DOWN, OnKeyDownLv1);
trace ("start");
}
public function Update(e:Event = null):void
{
updateBala();
mc.Update();
Coliciones();
if(Spawn_Boss)
{
boss.Update();
}
}
public function OnKeyUpLv1(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.SPACE:
disparo = true;
if (disparo == true)
{
var bala:Bullet = new Bullet();
bala.inicializar(mc.grafica.x, mc.grafica.y - mc.grafica.height/2 , mc.grafica.scaleX);
}
break;
}
}
public function OnKeyDownLv1(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.SPACE:
disparo = false;
break;
}
}
public function Coliciones():void
{
for(var i:int = 0; i < balaVector.length ;i++)
{
if(balaVector[i].grafica_1.hitTestObject(Ene.grafica))
{
Ene.Destroy();
balaVector[i].Destruir();
boss.Init(600,650);
Spawn_Boss = true;
break;
}
if(balaVector[i].grafica_1.hitTestObject(boss.grafica))
{
boss.Destroy();
balaVector[i].Destruir();
break;
}
}
if(mc.grafica.hitTestObject(Ene.grafica))
{
mc.grafica.x = mc.grafica.x - 3;
mc.vida --;
}
if(mc.grafica.hitTestObject(boss.grafica))
{
mc.vida -5;
}
}
public function updateBala():void
{
for(var i:int=0;i<balaVector.length;i++)
{
balaVector[i].BulletUpdate();
}
}
public function EndGame():void
{
mc.Destroy();
Main.escenario.removeEventListener(Event.ENTER_FRAME,Update);
}
}
And this is the class of the bullets.
public class Bullet
{
public var grafica_1:MC_Bala_1;
public var velocidad_1:int = 15;
public var damage_1:int = 1;
public var direccion:int = 0;
public function Bullet()
{
}
public function BulletUpdate():void
{
Mover();
}
public function inicializar(posX:int , posY:int , dir:int):void
{
grafica_1 = new MC_Bala_1();
grafica_1.x = posX;
grafica_1.y = posY;
this.direccion = dir;
Game.balaVector.push(this);
Main.escenario.addChild(grafica_1);
trace ("bala");
}
public function Mover():void
{
grafica_1.x += velocidad_1 * direccion;
if (grafica_1.x < 0 || grafica_1.x > Main.escenario.stageWidth)
{
Destruir();
}
}
public function Destruir():void
{
if (Main.escenario.contains(grafica_1)) Main.escenario.removeChild(grafica_1);
Game.balaVector.splice(Game.balaVector.indexOf(this),1);
trace ("destruir bala");
}
}
your multiplying your velocity * direction, 15*0 = 0, which is why its not moving
So basically this is a question about why my calling class (Door) can not identify this static variable class (Game State). it is throwing a #1009 error saying I can not access with GameState.gameState. On my stage I have a Symbol (CampaignLevel_001) that contains additional symbols like the calling symbol (Door) and above that as a separate Symbol (GameState) so essentially I am having trouble getting a nested symbol / class talking to another class.
package game.GameStates
{
import game.Assets.Player;
import game.Assets.Turret;
import game.Assets.Door;
import flash.events.Event;
import flash.display.MovieClip;
import flash.geom.Point;
import game.Levels.CampaignLevel_001;
public class GameState extends MovieClip
{
//VARIABLES
public var enemyArray : Array;
public var Bullets : Array = new Array();
public var Keys : Array = new Array();
public var HeldKeys : Array = new Array ();
public var Door : Array = new Array();
public var Terrain : Array = new Array();
public var Turrets : Array = new Array ();
public var Blood : Array = new Array ();
public var Shields : Array = new Array ();
public var Levels : Array = new Array ();
public var NumKeys : int;
public var DoorLock : Boolean = false;
public var PlayerSpawnPoint : Point;
public var CampaignSpawnPoint : Point;
public static var gameState : GameState;
public var player : Player;
public var turret : Turret;
public var PlayerLives : int = 99;
public function GameState()
{ // constructor code
gameState = this;
addEventListener(Event.ADDED_TO_STAGE, Awake);
} // constructor code
private function Awake (e : Event) : void
{
enemyArray = new Array();
trace(enemyArray.length);
}
public function OpenDoor () : void
{
if (NumKeys <= 0)
{
DoorLock = true;
}
if (NumKeys > 0)
{
DoorLock = false;
}
}
public function NextLevel () : void
{
RemoveListeners();
trace("SHOULD BE GOING TO THE NEXT LEVEL");
while (Levels.length > 0)
{
for each (var level in Levels)
{
level.NextLevel ();
}
}
}
public function RespawnPlayer () : void
{
//Spawn Player at player start point
player = new Player();
player.x = PlayerSpawnPoint.x;
player.y = PlayerSpawnPoint.y;
addChild(player);
trace("PLAYER ARRAY IS THIS LONG " + enemyArray.length);
trace("spawned Player!");
}
public function setSpellIcons (spell : String , opacity : int) : void
{
if (spell == "dodge")
{
if (opacity == 0)
{
dodgeSymbol.alpha = 0;
}
if (opacity == 1)
{
dodgeSymbol.alpha = 1;
}
}
if (spell == "shield")
{
if (opacity == 0)
{
shieldSymbol.alpha = 0;
}
if (opacity == 1)
{
shieldSymbol.alpha = 1;
}
}
} //public function setSpellIcons (spell : String , opacity : int) : void
public function RemoveListeners() : void
{
while (enemyArray.length > 0)
{
for each (var enemy : MovieClip in enemyArray)
{
enemy.RemovePlayer ();
}
}
while (Door.length > 0)
{
for each (var door : MovieClip in Door)
{
door.RemoveDoorFunctions ();
}
}
while (Bullets.length > 0)
{
for each (var bullet : MovieClip in Bullets)
{
bullet.RemoveProjectile();
}
}
while (Keys.length > 0)
{
for each (var key : MovieClip in Keys)
{
key.RemoveKey ();
}
}
while (Terrain.length > 0)
{
for each (var terrain : MovieClip in Terrain)
{
terrain.RemoveTerrainListeners();
}
}
while (Turrets.length > 0)
{
for each (var turret in Turrets)
{
turret.RemoveTurretListeners();
}
}
while (Blood.length > 0)
{
for each (var splatter in Blood)
{
splatter.RemoveBlood();
}
}
while (Shields.length > 0)
{
for each (var shield in Shields)
{
shield.RemoveShield();
}
}
} //public function RemoveListeners() : void
}
}
The Class that holds (door)
package game.Levels
{
import game.GameStates.GameState;
import flash.display.MovieClip;
import flash.events.Event;
public class CampaignLevel_001 extends MovieClip
{
var currentLevel : int = currentFrame;
public function CampaignLevel_001()
{ // constructor code
addEventListener(Event.ADDED_TO_STAGE, Awake);
}
private function Awake (e : Event) : void
{
GameState.gameState.Levels.push(this);
gotoAndStop(currentLevel);
trace ("CURRENT LEVEL IS " + currentLevel);
}
public function NextLevel () : void
{
var nextLevel : int = currentFrame + 1;
gotoAndStop(nextLevel);
trace ("NEXT LEVEL IS " + nextLevel);
}
}
}
and the calling class (door) is
package game.Assets
{
import flash.display.MovieClip;
import flash.events.Event;
import game.GameStates.GameState;
public class Door extends MovieClip
{
public function Door()
{ // constructor code
addEventListener(Event.ADDED_TO_STAGE, Awake);
}
private function Awake (e : Event) : void
{
GameState.gameState.Door.push(this);
GameState.gameState.OpenDoor ();
stage.addEventListener(Event.ENTER_FRAME, update);
open.alpha = 0;
}
private function update (e : Event) : void
{
if (GameState.gameState.DoorLock == true)
{
open.alpha = 1;
}
if (GameState.gameState.DoorLock == false)
{
open.alpha = 0;
}
}
public function RemoveDoorFunctions () : void
{
GameState.gameState.Door.splice(GameState.gameState.Door.indexOf(this),1);
stage.removeEventListener(Event.ENTER_FRAME, update);
parent.removeChild(this);
}
}
}
It looks like you're trying to make a Singleton, but haven't added the instance function.
change this:
public static var gameState:GameState;
to:
private static var _gameState:GameState;
and remove the constructor gamestate = this;
and add a function:
public static function get gameState():GameState {
if{_gameState == null) {
_gameState = new GameState();
}
return _gameState;
}
You can then call it and only get the one instance of GameState by:
GameState.gameState.DoorLock == true;
and any other function in GameState the same way
How do i change properties of the constructor class from a starling class I just added to it. or how do i call a function from the staring class that is a property of the mainClass
In my case how to change the alpha of an object in the mainClass of the FLA, from the starling class ( PuzzleGame ) and viceversa .
I have this:
public class MainClass extends Sprite
{
private var myStarling:Starling;
public var square:Sprite;
public function MainClass()
{
myStarling = new Starling( PuzzleGame, stage);
myStarling.start();
createAbox();
}
public function SendText()
{
trace("we are changing this in the main class")
}
public function createAbox()
{
square = new Sprite();
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,100,100);
square.graphics.endFill();
square.x = 100;
square.y = 100;
square.alpha = 0.5;
addChild(square);
square.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(ev:MouseEvent):void
{
this.square.alpha = 1;
//here how do i make the circle.alpha = 0.5;
//circle is an object created in the PuzzleGame
}
and
public class PuzzleGame extends Sprite
{
public var circle:Image;
public function PuzzleGame()
{
super();
trace("you are in PuzzleGame");
var s2:flash.display.Shape = new flash.display.Shape ;
s2.graphics.beginFill(0xff0000,1);
s2.graphics.drawCircle(40,40,40);
s2.graphics.endFill();
var bmpData:BitmapData = new BitmapData(100,100);
bmpData.draw(s2);
circle = Image.fromBitmap(new Bitmap(bmpData));
circle.x = 400;
circle.y = 150;
circle.alpha = 0.5;
addChild(circle);
circle.addEventListener(TouchEvent.TOUCH,onTouch);
}
private function onTouch(e:TouchEvent):void
{
parent.SendText();
var touch:Touch = e.getTouch(circle);
if (touch)
{
if (touch.phase == TouchPhase.ENDED)
{
circle.alpha = 1;
//here how do i make the square.alpha = 0.5
//something like parent.square.alpha = 0.5
}
}
}
The easiest way is to create a static method in your mainclass. something like:
public static function get starlingInstance():Starling(return mStarling);}
or
public static function get mainClass():MainClass(return this);}
So, I got this .as file that is called, let say, class A.
class A inside has other 2 classes, class B and class C, and the only class that is inside a package is class A. And it throws that error.
I downloaded this as an example, and it should work, however Flash Builder 4.6 doesn't like it.
The structure of the as file is like this:
imports
variables
class B
class C
package
public class A
/package
Btw, I'm using Flash Builder not Flash CC.
Update, posting code:
import com.adobe.serialization.json.JSON;
import com.shephertz.appwarp.WarpClient;
import com.shephertz.appwarp.listener.ConnectionRequestListener;
import com.shephertz.appwarp.listener.NotificationListener;
import com.shephertz.appwarp.listener.RoomRequestListener;
import com.shephertz.appwarp.listener.ZoneRequestListener;
import com.shephertz.appwarp.messages.Chat;
import com.shephertz.appwarp.messages.LiveResult;
import com.shephertz.appwarp.messages.LiveRoom;
import com.shephertz.appwarp.messages.LiveUser;
import com.shephertz.appwarp.messages.Lobby;
import com.shephertz.appwarp.messages.MatchedRooms;
import com.shephertz.appwarp.messages.Move;
import com.shephertz.appwarp.messages.Room;
import com.shephertz.appwarp.types.ResultCode;
import flash.utils.ByteArray;
var APIKEY:String = "key";
var SECRETEKEY:String = "secretkey";
var Connected:Boolean = false;
var INITIALIZED:Boolean = false;
var client:WarpClient;
var roomID:String;
var State:int = 0;
var User:String;
class connectionListener implements ConnectionRequestListener
{
private var connectFunc:Function;
public function connectionListener(f:Function)
{
connectFunc = f;
}
public function onConnectDone(res:int):void
{
if(res == ResultCode.success)
{
Connected = true;
}
else
{
Connected = false;
}
connectFunc(res);
}
public function onDisConnectDone(res:int):void
{
Connected = false;
}
}
class roomListener implements RoomRequestListener
{
private var connectFunc:Function;
private var joinFunc:Function;
public function roomListener(f:Function,f1:Function)
{
connectFunc = f;
joinFunc = f1;
}
public function onSubscribeRoomDone(event:Room):void
{
if(State == 2)
joinFunc();
else
connectFunc();
}
public function onUnsubscribeRoomDone(event:Room):void
{
}
public function onJoinRoomDone(event:Room):void
{
if(event.result == ResultCode.resource_not_found)
{
if(State == 1)
{
State = 3;
}
client.createRoom("room","admin",2,null);
}
else if(event.result == ResultCode.success)
{
if(State == 1)
{
State = 2;
}
roomID = event.roomId;
client.subscribeRoom(roomID);
}
}
public function onLeaveRoomDone(event:Room):void
{
client.unsubscribeRoom(roomID);
}
public function onGetLiveRoomInfoDone(event:LiveRoom):void
{
}
public function onSetCustomRoomDataDone(event:LiveRoom):void
{
}
public function onUpdatePropertyDone(event:LiveRoom):void
{
}
public function onLockPropertiesDone(result:int):void
{
}
public function onUnlockPropertiesDone(result:int):void
{
}
public function onUpdatePropertiesDone(event:LiveRoom):void
{
}
}
class zoneListener implements ZoneRequestListener
{
public function onCreateRoomDone(event:Room):void
{
roomID = event.roomId;
client.joinRoom(roomID);
}
public function onDeleteRoomDone(event:Room):void
{
}
public function onGetLiveUserInfoDone(event:LiveUser):void
{
}
public function onGetAllRoomsDone(event:LiveResult):void
{
}
public function onGetOnlineUsersDone(event:LiveResult):void
{
}
public function onSetCustomUserInfoDone(event:LiveUser):void
{
}
public function onGetMatchedRoomsDone(event:MatchedRooms):void
{
}
}
class notifylistener implements NotificationListener
{
private var joinFunc:Function;
private var msgFunc:Function;
private var leaveFunc:Function;
public function notifylistener(f:Function)
{
joinFunc = f;
}
public function msgListener(f:Function,f1:Function):void
{
msgFunc = f;
leaveFunc = f1;
}
public function onRoomCreated(event:Room):void
{
}
public function onRoomDestroyed(event:Room):void
{
}
public function onUserLeftRoom(event:Room, user:String):void
{
if(user != User)
{
leaveFunc();
}
}
public function onUserJoinedRoom(event:Room, user:String):void
{
if(State == 3)
joinFunc();
}
public function onUserLeftLobby(event:Lobby, user:String):void
{
}
public function onUserJoinedLobby(event:Lobby, user:String):void
{
}
public function onChatReceived(event:Chat):void
{
if(event.sender != User)
{
var obj:Object = com.adobe.serialization.json.JSON.decode(event.chat);
msgFunc(obj);
}
}
public function onUpdatePeersReceived(update:ByteArray):void
{
}
public function onUserChangeRoomProperty(room:Room, user:String,properties:Object):void
{
}
public function onPrivateChatReceived(sender:String, chat:String):void
{
}
public function onUserChangeRoomProperties(room:Room, user:String,properties:Object, lockTable:Object):void
{
}
public function onMoveCompleted(move:Move):void
{
}
}
package
{
import com.adobe.serialization.json.JSON;
import com.shephertz.appwarp.WarpClient;
public class AppWarp
{
public static var _roomlistener:roomListener;
public static var _zonelistener:zoneListener;
public static var _notifylistener:notifylistener;
public static var _connectionlistener:connectionListener;
private static function generateRandomString(strlen:Number):String{
var chars:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var num_chars:Number = chars.length - 1;
var randomChar:String = "";
for (var i:Number = 0; i < strlen; i++){
randomChar += chars.charAt(Math.floor(Math.random() * num_chars));
}
return randomChar;
}
public static function connect(f:Function):void
{
if(INITIALIZED == false)
{
WarpClient.initialize(APIKEY, SECRETEKEY);
client = WarpClient.getInstance();
INITIALIZED = true;
}
if(Connected == false)
{
_connectionlistener = new connectionListener(f);
client.setConnectionRequestListener(_connectionlistener);
User = generateRandomString(16);
client.connect(User);
}
else
f(0);
}
public static function join(f1:Function, f2:Function):void
{
_roomlistener = new roomListener(f1,f2);
_zonelistener = new zoneListener();
_notifylistener = new notifylistener(f2);
client.setRoomRequestListener(_roomlistener);
client.setZoneRequestListener(_zonelistener);
client.setNotificationListener(_notifylistener);
State = 1;
client.joinRoomInRange(1,1,true);
}
public static function leave():void
{
client.leaveRoom(roomID);
}
public static function begin(f:Function, f1:Function, dir:int, x:int, y:int):void
{
_notifylistener.msgListener(f, f1);
send(0,dir,x,y);
}
public static function move(dir:int,x:int,y:int):void
{
send(1,dir,x,y);
}
public static function eat(dir:int,x:int,y:int):void
{
send(2,dir,x,y);
}
public static function send(type:int,dir:int,x:int,y:int):void
{
if(Connected == true)
{
var obj:Object = new Object();
obj.type = type;
obj.dir = dir;
obj.x = x;
obj.y = y;
client.sendChat(com.adobe.serialization.json.JSON.encode(obj));
}
}
}
}
I needed to place the package keyword at the very beginning of the .as file, otherwise an error is thrown.
You can only define one class in a package in a file. You can define other classes outside the package, but I don't think that is a good idea as I have observed that in some versions of compiler you have to place it at the beginning and in some at the end. Sometimes, it won't work in anyway.
A better way is to define different classes for each listener in different files. You can use the same package name.
I would recommend creating a single class to listen to all listeners by implementing all base listener classes.
For e.g.
//listener.as
package
{
public class Listener implements ConnectionRequestListener, RoomRequestListener, NotificationListener
{
}
}
I'm new to flash in general and have been writing a program with two classes that extend MovieClip (Stems and Star).
I need to create a new Stems object as a child of the scene when the user stops dragging a Star object, but do not know how to reference the scene from within the Star class's code.
I've tried passing the scene into the constructor of the Star and doing sometihng like:
this.scene.addChild (new Stems ());
But apparently that's not how to do it... Below is the code for Stems and Stars, any advice would be appreciated greatly.
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.utils.Timer;
public class Stems extends MovieClip {
public const centreX=1026/2;
public const centreY=600/2;
public var isFlowing:Boolean;
public var flowerType:Number;
public const outerLimit=210;
public const innerLimit=100;
public function Stems(fType:Number) {
this.isFlowing=false;
this.scaleX=this.scaleY= .0007* distanceFromCentre(this.x, this.y);
this.setXY();
trace(distanceFromCentre(this.x, this.y));
if (fType==2) {
gotoAndStop("Aplant");
}
}
public function distanceFromCentre(X:Number, Y:Number):int {
return (Math.sqrt((X-centreX)*(X-centreX)+(Y-centreY)*(Y-centreY)));
}
public function rotateAwayFromCentre():void {
var theX:int=centreX-this.x;
var theY:int = (centreY - this.y) * -1;
var angle = Math.atan(theY/theX)/(Math.PI/180);
if (theX<0) {
angle+=180;
}
if (theX>=0&&theY<0) {
angle+=360;
}
this.rotation = ((angle*-1) + 90)+180;
}
public function setXY() {
do {
var tempX=Math.random()*centreX*2;
var tempY=Math.random()*centreY*2;
} while (distanceFromCentre (tempX, tempY)>this.outerLimit ||
distanceFromCentre (tempX, tempY)<this.innerLimit);
this.x=tempX;
this.y=tempY;
rotateAwayFromCentre();
}
public function getFlowerType():Number {
return this.flowerType;
}
}
}
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.utils.Timer;
public class Star extends MovieClip {
public const sWide=1026;
public const sTall=600;
public var startingX:Number;
public var startingY:Number;
public var starColor:Number;
public var flicker:Timer;
public var canUpdatePos:Boolean=true;
public const innerLimit=280;
public function Star(color:Number, basefl:Number, factorial:Number) {
this.setXY();
this.starColor=color;
this.flicker = new Timer (basefl + factorial * (Math.ceil(100* Math.random ())));
this.flicker.addEventListener(TimerEvent.TIMER, this.tick);
this.addEventListener(MouseEvent.MOUSE_OVER, this.hover);
this.addEventListener(MouseEvent.MOUSE_UP, this.drop);
this.addEventListener(MouseEvent.MOUSE_DOWN, this.drag);
this.addChild (new Stems (2));
this.flicker.start();
this.updateAnimation(0, false);
}
public function distanceOK(X:Number, Y:Number):Boolean {
if (Math.sqrt((X-(sWide/2))*(X-(sWide/2))+(Y-(sTall/2))*(Y-(sTall/2)))>innerLimit) {
return true;
} else {
return false;
}
}
public function setXY() {
do {
var tempX=this.x=Math.random()*sWide;
var tempY=this.y=Math.random()*sTall;
} while (distanceOK (tempX, tempY)==false);
this.startingX=tempX;
this.startingY=tempY;
}
public function tick(event:TimerEvent) {
if (this.canUpdatePos) {
this.setXY();
}
this.updateAnimation(0, false);
this.updateAnimation(this.starColor, false);
}
public function updateAnimation(color:Number, bright:Boolean) {
var brightStr:String;
if (bright) {
brightStr="bright";
} else {
brightStr="low";
}
switch (color) {
case 0 :
this.gotoAndStop("none");
break;
case 1 :
this.gotoAndStop("N" + brightStr);
break;
case 2 :
this.gotoAndStop("A" + brightStr);
break;
case 3 :
this.gotoAndStop("F" + brightStr);
break;
case 4 :
this.gotoAndStop("E" + brightStr);
break;
case 5 :
this.gotoAndStop("S" + brightStr);
break;
}
}
public function hover(event:MouseEvent):void {
this.updateAnimation(this.starColor, true);
this.canUpdatePos=false;
}
public function drop(event:MouseEvent):void {
this.stopDrag();
this.x=this.startingX;
this.y=this.startingY;
this.updateAnimation(0, false);
this.canUpdatePos=true;
}
public function drag(event:MouseEvent):void {
this.startDrag(false);
this.canUpdatePos=false;
}
}
}
The fastest way would be to use the parent variable which references the DisplayObject parent.
var stem:Stems = new Stems(2);
stem.x = x; //optional: set stem coordinates to that of Star
stem.y = y;
parent.addChild(stem);
If you want to add the Stems object to the stage every time a star-drag action stops you need to put the above code inside your drop function.