Re: [Flashcoders] Question about Arrays
Wow, thx Erik. Great answer! I buy into that. -mL EECOLOR wrote: I believe it's type * so you should cast it. This has nothing to do with that, hehe. There is a tiny difference beween ClassToCastTo(value) and (value as ClassToCastTo). In the first case a compiler error will be thrown. In the second case the cast will be tried. If it fails the resulting value will be a null value. why is -it- working The pop method is typed as Object. Object is a dynamic class which means you can add properties at runtime. This in turn means that the compiler can not complain about you calling a property that might not exist as you might be adding it 'dynamically' before you call it, Greetz Erik On 1/12/08, Mark Winterhalder [EMAIL PROTECTED] wrote: On Jan 11, 2008 11:34 PM, Mark Lapasa [EMAIL PROTECTED] wrote: I too would expect that it would need to be casted. Yes, one would think so. I can't answer your question, either, but can't help but note that in haXe you would declare your array as ArrayMyClass. The compiler wouldn't let you put anything else into it, and likewise, everything you'd pull out would be of type MyClass. haXe has a great type system (including implied types and type templates), so if you're the kind of coder that wonders about issues like that, I recommend you have a llok at http://haxe.org. Mark ___ 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 Notice of confidentiality: The information contained in this e-mail is intended only for the use of the individual or entity named above and may be confidential. Should the reader of this message not be the intended recipient, you are hereby notified that any unauthorized dissemination, distribution or reproduction of this message is strictly prohibited. If you have received this message in error, please advise the sender immediately and destroy the e-mail. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Question about Arrays
I believe it's type * so you should cast it. This has nothing to do with that, hehe. There is a tiny difference beween ClassToCastTo(value) and (value as ClassToCastTo). In the first case a compiler error will be thrown. In the second case the cast will be tried. If it fails the resulting value will be a null value. why is -it- working The pop method is typed as Object. Object is a dynamic class which means you can add properties at runtime. This in turn means that the compiler can not complain about you calling a property that might not exist as you might be adding it 'dynamically' before you call it, Greetz Erik On 1/12/08, Mark Winterhalder [EMAIL PROTECTED] wrote: On Jan 11, 2008 11:34 PM, Mark Lapasa [EMAIL PROTECTED] wrote: I too would expect that it would need to be casted. Yes, one would think so. I can't answer your question, either, but can't help but note that in haXe you would declare your array as ArrayMyClass. The compiler wouldn't let you put anything else into it, and likewise, everything you'd pull out would be of type MyClass. haXe has a great type system (including implied types and type templates), so if you're the kind of coder that wonders about issues like that, I recommend you have a llok at http://haxe.org. Mark ___ 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] Question about Arrays
Hello :) try the typecasting : (a.pop() as MyClass).myFunction(); you can decompose the code with a reference and add a test with the null object var myInstance:MyClass = a.pop() as MyClass ; if ( myInstance != null ) { myInstance.myFunction() ; } EKA+ :) 2008/1/11, Mark Lapasa [EMAIL PROTECTED]: In the following bit of code... // START code package { import flash.display.Sprite; public class SampleClass extends Sprite { public function SampleClass() { var a:Array = [new MyClass()]; a[0].myFunction(); a.pop().myFunction(); } } } class MyClass { public function myFunction():void { trace(you should see this twice); } } // END code Does accessing the array (or poping an element off it) return something of type Object? or type MyClass? myFunction() is a part of the interface of MyClass so I am guessing when objects are stored in arrays, their type is also stored in the array as well. Thx, -mL knowledge.lapasa.net Notice of confidentiality: The information contained in this e-mail is intended only for the use of the individual or entity named above and may be confidential. Should the reader of this message not be the intended recipient, you are hereby notified that any unauthorized dissemination, distribution or reproduction of this message is strictly prohibited. If you have received this message in error, please advise the sender immediately and destroy the e-mail. ___ 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] Question about Arrays
I believe it's type * so you should cast it. MyClass(a[0]).myFunction(); Mark Lapasa wrote: In the following bit of code... // START code package { import flash.display.Sprite; public class SampleClass extends Sprite { public function SampleClass() { var a:Array = [new MyClass()]; a[0].myFunction(); a.pop().myFunction(); } } } class MyClass { public function myFunction():void { trace(you should see this twice); } } // END code Does accessing the array (or poping an element off it) return something of type Object? or type MyClass? myFunction() is a part of the interface of MyClass so I am guessing when objects are stored in arrays, their type is also stored in the array as well. Thx, -mL knowledge.lapasa.net Notice of confidentiality: The information contained in this e-mail is intended only for the use of the individual or entity named above and may be confidential. Should the reader of this message not be the intended recipient, you are hereby notified that any unauthorized dissemination, distribution or reproduction of this message is strictly prohibited. If you have received this message in error, please advise the sender immediately and destroy the e-mail. ___ 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] Question about Arrays
In the following bit of code... // START code package { import flash.display.Sprite; public class SampleClass extends Sprite { public function SampleClass() { var a:Array = [new MyClass()]; a[0].myFunction(); a.pop().myFunction(); } } } class MyClass { public function myFunction():void { trace(you should see this twice); } } // END code Does accessing the array (or poping an element off it) return something of type Object? or type MyClass? myFunction() is a part of the interface of MyClass so I am guessing when objects are stored in arrays, their type is also stored in the array as well. Thx, -mL knowledge.lapasa.net Notice of confidentiality: The information contained in this e-mail is intended only for the use of the individual or entity named above and may be confidential. Should the reader of this message not be the intended recipient, you are hereby notified that any unauthorized dissemination, distribution or reproduction of this message is strictly prohibited. If you have received this message in error, please advise the sender immediately and destroy the e-mail. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Question about Arrays
Thx eka + steven for your replies. Forgot to mention my question which is not why is this -not- working Rather why is -it- working? Try creating an AS3 project in Flex called SampleClass. Cut and paste the whole code. I too would expect that it would need to be casted. Thx, -mL knowledge.lapasa.net Steven Sacks wrote: I believe it's type * so you should cast it. MyClass(a[0]).myFunction(); Mark Lapasa wrote: In the following bit of code... // START code package { import flash.display.Sprite; public class SampleClass extends Sprite { public function SampleClass() { var a:Array = [new MyClass()]; a[0].myFunction(); a.pop().myFunction(); } } } class MyClass { public function myFunction():void { trace(you should see this twice); } } // END code Does accessing the array (or poping an element off it) return something of type Object? or type MyClass? myFunction() is a part of the interface of MyClass so I am guessing when objects are stored in arrays, their type is also stored in the array as well. Thx, -mL knowledge.lapasa.net Notice of confidentiality: The information contained in this e-mail is intended only for the use of the individual or entity named above and may be confidential. Should the reader of this message not be the intended recipient, you are hereby notified that any unauthorized dissemination, distribution or reproduction of this message is strictly prohibited. If you have received this message in error, please advise the sender immediately and destroy the e-mail. ___ 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 Notice of confidentiality: The information contained in this e-mail is intended only for the use of the individual or entity named above and may be confidential. Should the reader of this message not be the intended recipient, you are hereby notified that any unauthorized dissemination, distribution or reproduction of this message is strictly prohibited. If you have received this message in error, please advise the sender immediately and destroy the e-mail. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Question about Arrays
On Jan 11, 2008 11:34 PM, Mark Lapasa [EMAIL PROTECTED] wrote: I too would expect that it would need to be casted. Yes, one would think so. I can't answer your question, either, but can't help but note that in haXe you would declare your array as ArrayMyClass. The compiler wouldn't let you put anything else into it, and likewise, everything you'd pull out would be of type MyClass. haXe has a great type system (including implied types and type templates), so if you're the kind of coder that wonders about issues like that, I recommend you have a llok at http://haxe.org. Mark ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders