Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Access of undefined property ERROR

Explorer ,
May 06, 2014 May 06, 2014

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.

TOPICS
ActionScript
341
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 06, 2014 May 06, 2014

stoneblock is not defined in the Blockholder class.  When you instantiate a Blockholder object it has nothing to know what stoneblock is.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 06, 2014 May 06, 2014

So in the blockholder class, do I do public var stoneblock:StoneBlock = new Stoneblock?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 06, 2014 May 06, 2014
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines