I’m having a problem by using classes. I used this tutorial online:
http://www.youtube.com/watch?v=ALqGYMsRWxw
My problem is in this tutorial he is using objects on the stage. What I want to do is add the object from out of code and use this exact same code. So that the stage is empty and when you run the project it will add the objects which you can drag.
Game.as (this is where import my class)
package
{
import flash.display.MovieClip;
import classes.tools.Tools;
import classes.tools.ToolType1;
public class Game extends MovieClip
{
var tool1:classes.tools.ToolType1 = new classes.tools.ToolType1();
public function Game()
{
addChild(tool1);
}
}
}
Tools (this is what is called DraggableShirt in the tutorial)
package classes.tools
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;
public class Tools extends MovieClip
{
var originalPosition:Point;
public function Tools()
{
originalPosition = new Point(x,y);
buttonMode = true;
parent.addChild(this);
this.addEventListener(MouseEvent.MOUSE_DOWN, drag);
}
// als je de muis indrukt dan pak je een voorwerp op
function drag(evnt:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
this.startDrag();
//scaling
this.scaleY = 1.5;
this.scaleX = 1.5;
}
// als je de muis loslaat laat je het voorwerp los
function drop(e:MouseEvent):void
{
//positioning van de tools
//Delete knop
//bewerk knop
stage.removeEventListener(MouseEvent.MOUSE_UP, drop);
stopDrag()
if(dropTarget)
{
if(dropTarget.parent.name == "trash")
{
}
else
{
returnToOriginalPosition();
}
}
else
{
returnToOriginalPosition();
}
}
function returnToOriginalPosition():void
{
x = originalPosition.x;
y = originalPosition.y;
this.scaleX = 1;
this.scaleY = 1;
}
}
}
ToolType1 (this is what is called WhiteShirt/BlackShirt in the tutorial)
package classes.tools
{
public class ToolType1 extends Tools
{
}
}
After having a quick look at video 1 of 3, i’d say you already get that.
He just places his stuff on the stage for easy testing/showing.
What your looking for is code along the lines of;
Im not sure if you will need the first line, its something i used a while ago when i was using Classes with strings i sent back and forth between swfs, try see if it works without, else just keep it. (note that this code should go in the fla file, or even better a ‘Main.as’ file attached to the fla file)