Copy link to clipboard
Copied
I have a piece of code that adds a child through a sprite, I am now trying to access that child by doing SPRITE_NAME.CHILD.PROPERTY (blockholder.stoneblock.myProperty)
But I get this error:
BlockHolder.as, Line 14 1120: Access of undefined property stoneblock.
Here is my code where I try to access stoneblock
package {
import flash.display.Sprite
public class BlockHolder extends Sprite {
public function BlockHolder() {
}
public function checkScroll():void
{
stoneblock.checkScroll();
}
}
}
And here is where I add stoneblock to blockholder:
var dirtblock:DirtBlock = new DirtBlock();
var stoneblock:StoneBlock = new StoneBlock ;
if (blockY >= 9)
{
checkCave();
if (Global.vars.cave == true)
{
}
else
{
stoneblock.x = i * 10;
stoneblock.y = blockY * 10 - 10;
blockholder.addChild(stoneblock);
listofblocks = stoneblock.x + "," + stoneblock.y;
}
}
else
{
dirtblock.x = i * 10;
dirtblock.y = blockY*10 - 10
;
blockholder.addChild(dirtblock);
listofblocks = dirtblock.x + "," + dirtblock.y;
}
if (i == 100 && blockY < 100)
{
blockY++;
i = 0;
gamescroll.update();
}
I also tried doing blockholder.stoneblock.myProperty through the game.as, but that didn't work.
I am trying to do things to these blocks, and am needing someone to point me in the right direction, any help would be greatly appreciated.
Copy link to clipboard
Copied
stoneblock is not defined in the Blockholder class. When you instantiate a Blockholder object it has nothing to know what stoneblock is.
Copy link to clipboard
Copied
So in the blockholder class, do I do public var stoneblock:StoneBlock = new Stoneblock?
Copy link to clipboard
Copied
I would try starting with declaring the stoneblock variable (public var stoneblock:StoneBlock;), be sure to import the class. If the Blockholder will always hold that object then have a function that creates the instance within the Blockholder class
Find more inspiration, events, and resources on the new Adobe Community
Explore Now