double tap manipulating array in different class. (less confusing inside)
Posted: 21 November 2008 10:46 AM   [ Ignore ]
Jr. Member
RankRank
Total Posts:  161
Joined  2008-05-31

I made an app that when you touch the screen it adds a sprite that is an instances of a class that extends rotateScalable (so each one is draggle).
after 5 have been added, I set it so it wont add anymore when you touch, and you can just move them around.
I do this by adding 1 to an array, and then say if array.length > 5 add one if not.... There is a reason for it being an array, and not a variable.

If you double tap one of them, I remove them, so then there is less than 5 on the table. I want to be able to tap again and add another, but, when I remove them, Im not able to remove it from the array and so it still thinks there are 5.

This is because the remove is done by the rotateScalable extended class, and not the document class where the array is.

Is there any way to fix that? Or get around it.

And again, I do need that array in the document class, it does a lot of other stuff.

Profile
 
 
Posted: 21 November 2008 11:27 AM   [ Ignore ]   [ # 1 ]
Jr. Member
Avatar
RankRank
Total Posts:  135
Joined  2007-03-15

you can add an event listener for when the rotateScalable class is removed from the stage, and in this event handler, remove the object from the array.

http://livedocs.adobe.com/flex/2/langref/flash/display/DisplayObject.html#event:removed

Profile
 
 
Posted: 21 November 2008 11:29 AM   [ Ignore ]   [ # 2 ]
Jr. Member
RankRank
Total Posts:  161
Joined  2008-05-31

Wow… really?
That’s awesome.
Thanks!

Pleh - 21 November 2008 11:27 AM

you can add an event listener for when the rotateScalable class is removed from the stage, and in this event handler, remove the object from the array.

Profile
 
 
Posted: 21 November 2008 11:35 AM   [ Ignore ]   [ # 3 ]
Jr. Member
Avatar
RankRank
Total Posts:  135
Joined  2007-03-15

Better still, just use the numChildren method to see how many objects are on the stage to determine whether or not you want to allow the user to add another.

if(stage.numChildren < 5){

Add away!

}

Profile
 
 
Posted: 21 November 2008 11:38 AM   [ Ignore ]   [ # 4 ]
Jr. Member
RankRank
Total Posts:  161
Joined  2008-05-31

Euphoria in a single sentence.
Any book you recommend to really know this stuff well?

Pleh - 21 November 2008 11:35 AM

Better still, just use the numChildren method to see how many objects are on the stage to determine whether or not you want to allow the user to add another.

if(stage.numChildren < 5){

Add away!

}

Profile
 
 
Posted: 22 November 2008 07:22 PM   [ Ignore ]   [ # 5 ]
Jr. Member
Avatar
RankRank
Total Posts:  135
Joined  2007-03-15

I’m dyslexic so I don’t read books I’m afraid, but http://www.actionscript.org is a very useful site for tutorials and has some very active forums.

Profile
 
 
   
 
 
‹‹ Alchemy      App Idea ››