Hello I don’t know why this is not working everything looks fine to me.
I am creating buttons and adding them to two static sprites _mainSprite to hold main buttons and _leftSprite to hold left buttons.
When I am tracing the value of _mainSprite.numChildren inside the constructor its coming out to be “4” which is the number of top buttons. BUT WHEN I TRACE THE SAME VALUE INSIDE A STATIC CLASS FUNCTION THAT RETURNS _MAINSPRITE ITS COMES OUT TO BE “0”.
I have tried everything and now need help.
Here is the code for my class
package
{
import flash.display.*;
public class CreateMenuItems extends Sprite
{
// Class properties
private static var _mainSprite:Sprite;
private static var _leftSprite:Sprite;
private var j:int = 0;
private var k:int = 0;
// Class Constructor
public function CreateMenuItems(mArray:Array)
{
_mainSprite = new Sprite();
_leftSprite = new Sprite();
for (var i:int = 0; i < mArray.length; i++)
{
var siteButton:DisablingButton = new DisablingButton(mArray*);
if ( mArray*.id == 0)
{
siteButton.x = siteButton.width * j;
_mainSprite.addChild(siteButton);
j++;
}
else
{
siteButton.y = siteButton.height * k ;
_leftSprite.addChild(siteButton);
k++;
}
} // end of for loop
**// If I trace here inside the constructor it gives 4**
trace(_mainSprite.numChildren);
} // end of constructor
public static function mainSprite():Sprite
{
** // If I trace here inside return sprite function it gives 0
** trace(_mainSprite.numChildren);
return _mainSprite;
}
public static function leftSprite():Sprite
{
return _leftSprite;
}
}
}
Thanks in advance