Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
To expand on this (since I'm now awake!) what method I use depends on how I want to access the child objects. If I just want a list to iterate over/trawl through, I use an Array. If I want to access by name, I use an Object. The reasons I don't normally directly rely on the the childlist of the container object include: - I can remove/add a child but still have a reference in the Array - I can do a bunch of stuff to those clips without affecting any other children of the container, like: iterate through the array, reorder/reindex just those children, delete just those children, _count_ just those children. - I don't have to worry about checking the return types of the objects in the array, because I know what's stored in there. Whereas using getChildByName(), I know I'm getting a DisplayObject back, but don't know exactly what type - I have to check. Those last few might seem a bit peculiar - why shouldn't I know exactly what the child objects are? This comes from two places: - I may mix arrays of different children into the same container (e.g. a bunch of target clips, a bunch of draggable clips - or, for a game, the player Sprite and the enemy Sprites). Having two arrays is much better than relying on the childList in this case. - I am not the only person working on this code, and can't rely on another coder not adding in a decorative background or border to my container, or an extra graphics, or... I hope that makes sense. And is a better answer than my earlier one. :-D (mmm... sweet caffeine...) Ian On Wed, Dec 17, 2008 at 2:28 AM, Matt S. mattsp...@gmail.com wrote: I wasnt actually the original question-asker, but thanks :) I was just curious about the actual performance hit from getChild. .m On Tue, Dec 16, 2008 at 5:57 PM, Taka Kojima t...@gigafied.com wrote: I use the method I gave you earlier, adding elements to an array and accessing them that way. Also, you can use getChildAt() if you know the index of the children, which it sounds like you do if you have them named as you do... i.e. column1, column2, column3 On Tue, Dec 16, 2008 at 2:17 PM, Matt S. mattsp...@gmail.com wrote: So as a general question, what is the preferred method if you're trying to get, say, dynamically generated children, eg image1image20 etc, from a container? .m On Tue, Dec 16, 2008 at 4:51 PM, Ian Thomas i...@eirias.net wrote: Yes. On Tue, Dec 16, 2008 at 9:08 PM, Anthony Pace anthony.p...@utoronto.ca wrote: isn't getting a child by name very slow? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
Thanks, but what I'm more interested in was the statement that getChildByName is very slow, which others seemed to agree with. I guess I understood that as meaning that using gCBN can actually cause a performance hit. Is that the case? .m On 12/17/08, Ian Thomas i...@eirias.net wrote: To expand on this (since I'm now awake!) what method I use depends on how I want to access the child objects. If I just want a list to iterate over/trawl through, I use an Array. If I want to access by name, I use an Object. The reasons I don't normally directly rely on the the childlist of the container object include: - I can remove/add a child but still have a reference in the Array - I can do a bunch of stuff to those clips without affecting any other children of the container, like: iterate through the array, reorder/reindex just those children, delete just those children, _count_ just those children. - I don't have to worry about checking the return types of the objects in the array, because I know what's stored in there. Whereas using getChildByName(), I know I'm getting a DisplayObject back, but don't know exactly what type - I have to check. Those last few might seem a bit peculiar - why shouldn't I know exactly what the child objects are? This comes from two places: - I may mix arrays of different children into the same container (e.g. a bunch of target clips, a bunch of draggable clips - or, for a game, the player Sprite and the enemy Sprites). Having two arrays is much better than relying on the childList in this case. - I am not the only person working on this code, and can't rely on another coder not adding in a decorative background or border to my container, or an extra graphics, or... I hope that makes sense. And is a better answer than my earlier one. :-D (mmm... sweet caffeine...) Ian On Wed, Dec 17, 2008 at 2:28 AM, Matt S. mattsp...@gmail.com wrote: I wasnt actually the original question-asker, but thanks :) I was just curious about the actual performance hit from getChild. .m On Tue, Dec 16, 2008 at 5:57 PM, Taka Kojima t...@gigafied.com wrote: I use the method I gave you earlier, adding elements to an array and accessing them that way. Also, you can use getChildAt() if you know the index of the children, which it sounds like you do if you have them named as you do... i.e. column1, column2, column3 On Tue, Dec 16, 2008 at 2:17 PM, Matt S. mattsp...@gmail.com wrote: So as a general question, what is the preferred method if you're trying to get, say, dynamically generated children, eg image1image20 etc, from a container? .m On Tue, Dec 16, 2008 at 4:51 PM, Ian Thomas i...@eirias.net wrote: Yes. On Tue, Dec 16, 2008 at 9:08 PM, Anthony Pace anthony.p...@utoronto.ca wrote: isn't getting a child by name very slow? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] referencing sprites within a sprite (AS3 newbie question)
Wow, AS3 is different, even after reading Moock's book. I'm sure this is an easy question: How do you reference sprites within a sprite in an event listener? I have a child allcolumns within a sprite. Within allcolumns are 50 columns (sprites), each named column1, column2, etc. Allcolumns has an event listener: private function changeChar(e:Event):void { e.target[column10].gotoAndStop(5); } Result: ReferenceError: Error #1069: Property column10 not found on flash.display.Sprite and there is no default value. How to drill into what's in the e.target? Thanks, - Michael M. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
Hey Michael, seeing as you can't create Sprites on the timeline, the following won't work because your sprites don't have instance names. Thus when you are creating your sprites, you have to add them all to an array. i.e. var columns:Array = new Array(); for(var i:int = 0; i = 50; i ++){ var column:Sprite = new Sprite(); allcolumns.addChild(column); columns.push(column); } private function changeChar(e:Event):void { columns[9].gotoAndStop(5); } On Tue, Dec 16, 2008 at 11:59 AM, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Wow, AS3 is different, even after reading Moock's book. I'm sure this is an easy question: How do you reference sprites within a sprite in an event listener? I have a child allcolumns within a sprite. Within allcolumns are 50 columns (sprites), each named column1, column2, etc. Allcolumns has an event listener: private function changeChar(e:Event):void { e.target[column10].gotoAndStop(5); } Result: ReferenceError: Error #1069: Property column10 not found on flash.display.Sprite and there is no default value. How to drill into what's in the e.target? Thanks, - Michael M. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
If each of the columns has .name='column1' etc: e.target.getChildByName(column10).gotoAndStop(5); should do it. But personally I'd at least do some type-checking on all that, and would probably create a method inside an AllColumns class to handle changeChar(). (Obviously I don't know what you're doing, though...) Ian On Tue, Dec 16, 2008 at 7:59 PM, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Wow, AS3 is different, even after reading Moock's book. I'm sure this is an easy question: How do you reference sprites within a sprite in an event listener? I have a child allcolumns within a sprite. Within allcolumns are 50 columns (sprites), each named column1, column2, etc. Allcolumns has an event listener: private function changeChar(e:Event):void { e.target[column10].gotoAndStop(5); } Result: ReferenceError: Error #1069: Property column10 not found on flash.display.Sprite and there is no default value. How to drill into what's in the e.target? Thanks, - Michael M. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
isn't getting a child by name very slow? Ian Thomas wrote: If each of the columns has .name='column1' etc: e.target.getChildByName(column10).gotoAndStop(5); should do it. But personally I'd at least do some type-checking on all that, and would probably create a method inside an AllColumns class to handle changeChar(). (Obviously I don't know what you're doing, though...) Ian On Tue, Dec 16, 2008 at 7:59 PM, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Wow, AS3 is different, even after reading Moock's book. I'm sure this is an easy question: How do you reference sprites within a sprite in an event listener? I have a child allcolumns within a sprite. Within allcolumns are 50 columns (sprites), each named column1, column2, etc. Allcolumns has an event listener: private function changeChar(e:Event):void { e.target[column10].gotoAndStop(5); } Result: ReferenceError: Error #1069: Property column10 not found on flash.display.Sprite and there is no default value. How to drill into what's in the e.target? Thanks, - Michael M. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
.currentTarget ? On Tue, Dec 16, 2008 at 4:51 PM, Ian Thomas i...@eirias.net wrote: Yes. However, it was the simplest answer to Michael's question. I'm afraid I didn't (and still don't) have time to answer the question with a long 'here's how I'd actually do it and why it's a good idea not to refer to nested clips like this' email, unfortunately. :-) It was a quick fix for Michael, and in the long term, you're right - the wrong answer. Perhaps I shouldn't comment at all when I'm this short of time. :-) But feel free to write your own answer, Anthony... Ian On Tue, Dec 16, 2008 at 9:08 PM, Anthony Pace anthony.p...@utoronto.ca wrote: isn't getting a child by name very slow? Ian Thomas wrote: If each of the columns has .name='column1' etc: e.target.getChildByName(column10).gotoAndStop(5); should do it. But personally I'd at least do some type-checking on all that, and would probably create a method inside an AllColumns class to handle changeChar(). (Obviously I don't know what you're doing, though...) Ian On Tue, Dec 16, 2008 at 7:59 PM, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Wow, AS3 is different, even after reading Moock's book. I'm sure this is an easy question: How do you reference sprites within a sprite in an event listener? I have a child allcolumns within a sprite. Within allcolumns are 50 columns (sprites), each named column1, column2, etc. Allcolumns has an event listener: private function changeChar(e:Event):void { e.target[column10].gotoAndStop(5); } Result: ReferenceError: Error #1069: Property column10 not found on flash.display.Sprite and there is no default value. How to drill into what's in the e.target? Thanks, - Michael M. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- http://ericd.net Interactive design and development ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
So as a general question, what is the preferred method if you're trying to get, say, dynamically generated children, eg image1image20 etc, from a container? .m On Tue, Dec 16, 2008 at 4:51 PM, Ian Thomas i...@eirias.net wrote: Yes. On Tue, Dec 16, 2008 at 9:08 PM, Anthony Pace anthony.p...@utoronto.ca wrote: isn't getting a child by name very slow? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
I use the method I gave you earlier, adding elements to an array and accessing them that way. Also, you can use getChildAt() if you know the index of the children, which it sounds like you do if you have them named as you do... i.e. column1, column2, column3 On Tue, Dec 16, 2008 at 2:17 PM, Matt S. mattsp...@gmail.com wrote: So as a general question, what is the preferred method if you're trying to get, say, dynamically generated children, eg image1image20 etc, from a container? .m On Tue, Dec 16, 2008 at 4:51 PM, Ian Thomas i...@eirias.net wrote: Yes. On Tue, Dec 16, 2008 at 9:08 PM, Anthony Pace anthony.p...@utoronto.ca wrote: isn't getting a child by name very slow? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
On Tue, Dec 16, 2008 at 10:57 PM, Taka Kojima t...@gigafied.com wrote: I use the method I gave you earlier, adding elements to an array and accessing them that way. As do I. Ian ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
Yes. However, it was the simplest answer to Michael's question. I'm afraid I didn't (and still don't) have time to answer the question with a long 'here's how I'd actually do it and why it's a good idea not to refer to nested clips like this' email, unfortunately. :-) It was a quick fix for Michael, and in the long term, you're right - the wrong answer. Perhaps I shouldn't comment at all when I'm this short of time. :-) But feel free to write your own answer, Anthony... Ian On Tue, Dec 16, 2008 at 9:08 PM, Anthony Pace anthony.p...@utoronto.ca wrote: isn't getting a child by name very slow? Ian Thomas wrote: If each of the columns has .name='column1' etc: e.target.getChildByName(column10).gotoAndStop(5); should do it. But personally I'd at least do some type-checking on all that, and would probably create a method inside an AllColumns class to handle changeChar(). (Obviously I don't know what you're doing, though...) Ian On Tue, Dec 16, 2008 at 7:59 PM, Mendelsohn, Michael michael.mendels...@fmglobal.com wrote: Wow, AS3 is different, even after reading Moock's book. I'm sure this is an easy question: How do you reference sprites within a sprite in an event listener? I have a child allcolumns within a sprite. Within allcolumns are 50 columns (sprites), each named column1, column2, etc. Allcolumns has an event listener: private function changeChar(e:Event):void { e.target[column10].gotoAndStop(5); } Result: ReferenceError: Error #1069: Property column10 not found on flash.display.Sprite and there is no default value. How to drill into what's in the e.target? Thanks, - Michael M. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] referencing sprites within a sprite (AS3 newbie question)
I wasnt actually the original question-asker, but thanks :) I was just curious about the actual performance hit from getChild. .m On Tue, Dec 16, 2008 at 5:57 PM, Taka Kojima t...@gigafied.com wrote: I use the method I gave you earlier, adding elements to an array and accessing them that way. Also, you can use getChildAt() if you know the index of the children, which it sounds like you do if you have them named as you do... i.e. column1, column2, column3 On Tue, Dec 16, 2008 at 2:17 PM, Matt S. mattsp...@gmail.com wrote: So as a general question, what is the preferred method if you're trying to get, say, dynamically generated children, eg image1image20 etc, from a container? .m On Tue, Dec 16, 2008 at 4:51 PM, Ian Thomas i...@eirias.net wrote: Yes. On Tue, Dec 16, 2008 at 9:08 PM, Anthony Pace anthony.p...@utoronto.ca wrote: isn't getting a child by name very slow? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders