PDA

View Full Version : Sprite Problem



adnan794
July 20th, 2008, 08:09 PM
Hello

I am making a portfolio page. I have a class called PotfolioList that creats Thumnails and adds it to a container sprite. This sprite can be reterived from other classes by calling a getSprite method.

When I call this method form another class the sprite does not contain anything. I am pasting the code for this class here.




// Class creats thumbnials and adds them to _pContainer sprite
public class PortfolioList extends Sprite
{
// Conatiner sprite to add thumbnails
private var _pContainer:Sprite;

public function PortfolioList()
{
_pContainer = new Sprite();

// this function creats 10 movie clips from PortfolioThumb class
for (var i:int = 0; i < 10; i++)
{
var pThumb:PortfolioThumb = new PortfolioThumb;
pThumb.x = (pThumb.width + 60) * i ;

// add thumnails to _pContainer Sprite
_pContainer.addChild(pThumb);
i++;

}
}
public function getSprite():Sprite
{

//return _pContainer containing all the thumbnails
return _pContainer;
}
}



If I use this in another class

var pList:PortfolioList = new PortfolioList;
trace(pList.getSprite().numChildren); // traces 0


Can anyone please help me on this?

Thanks

vonWolfehaus
July 20th, 2008, 09:21 PM
You don't need to increment i at the end of your for loop -- that's already done in the third param of the loop declaration (eg for (i = 0; i < something.length; i++) {...}). Unless you want to increment by 2 at a time...

As for the reference problem, it works just fine for me, so the problem is with your PortfolioThumb class. For example, replace PortfolioThumb with Sprite and it'll trace correctly (5 in your example, or 10 if you take out that extra i++ I mentioned).

adnan794
July 20th, 2008, 09:47 PM
Hello Thank you for your reply and I am sorry about the i++ things It was a mistake on my part while writing the problem.

I dont know how but the code is now working this is very strange. BUt thanks for your time anyway.

Regards
Adnan