TJones
11-21-2007, 10:17 PM
I've built bookoos of stuff in 2.0 and in just the past couple of days started to play with 3.0.
I have created a simple drag and drop isometric app that you can view here:
http://www.tangerinepop.com/experiments/AS3/IsoDrag/
Seems to be a problem with referencing the dropTarget. First of all I was suprised to find the need to parent up to my GridContainer. Seems the fill in the actual asset is what the dropTarget references (blue fill, then Tile object, then GridContainer object respectively).
So the problem happens when the mouse down event calls the line of code looking at the dropTarget reference:
if (this.dropTarget.parent.parent is GridContainer)
{
var d:DisplayObjectContainer = this.dropTarget.parent.parent;
d.addChild(this);
this.x = 0
this.y = (d.numChildren - 2) * -40;
} else {
startParent.addChild(this);
this.x = startParent.mouseX;
this.y = startParent.mouseY;
}
Any time the blocks are over the grid, there is no problem, however when over the stage (my main class), the error occurs.
To understand how my assets are nested (Tile class inside GridContainer class), here is the loop from the buildGrid function in my Main() class.
for (var z:uint = 0; z<Z; z++)
{
for (var x:uint = 0; x < X; x++)
{
var g:GridContainer = new GridContainer(x, z, tileWidth);
var t:Tile = new Tile();
g.addChild(t);
this.addChild(g);
}
}
Obviously the dropTarget.parent.parent is trying to reference a null when not over the tiles and thus the error. However, since I am just getting my feet wet in 3.0, does anyone know of a standard practice on how to handle this?
Thanks!
TJ
I have created a simple drag and drop isometric app that you can view here:
http://www.tangerinepop.com/experiments/AS3/IsoDrag/
Seems to be a problem with referencing the dropTarget. First of all I was suprised to find the need to parent up to my GridContainer. Seems the fill in the actual asset is what the dropTarget references (blue fill, then Tile object, then GridContainer object respectively).
So the problem happens when the mouse down event calls the line of code looking at the dropTarget reference:
if (this.dropTarget.parent.parent is GridContainer)
{
var d:DisplayObjectContainer = this.dropTarget.parent.parent;
d.addChild(this);
this.x = 0
this.y = (d.numChildren - 2) * -40;
} else {
startParent.addChild(this);
this.x = startParent.mouseX;
this.y = startParent.mouseY;
}
Any time the blocks are over the grid, there is no problem, however when over the stage (my main class), the error occurs.
To understand how my assets are nested (Tile class inside GridContainer class), here is the loop from the buildGrid function in my Main() class.
for (var z:uint = 0; z<Z; z++)
{
for (var x:uint = 0; x < X; x++)
{
var g:GridContainer = new GridContainer(x, z, tileWidth);
var t:Tile = new Tile();
g.addChild(t);
this.addChild(g);
}
}
Obviously the dropTarget.parent.parent is trying to reference a null when not over the tiles and thus the error. However, since I am just getting my feet wet in 3.0, does anyone know of a standard practice on how to handle this?
Thanks!
TJ