Re: [Flashcoders] interfaces and objects
Um... not quite sure what you're up to here - but it sounds like you're getting a bit confused between IWorldPart and WorldPart. What you need is: interface IWorldPart class SomeWorldPartSubclass implements IWorldPart then var myPart:IWorldPart = new SomeWorldPartSubclass(); should be fine. _OR_ interface WorldPart class SomeWorldPartSubclass implements WorldPart then var myPart:WorldPart = new SomeWorldPartSubclass(); Not quite sure why your description mentions both IWorldPart and WorldPart - unless WorldPart implements IWorldPart..? In which case you're looking for: interface IWorldPart class WorldPart implements IWorldPart class SomeWorldPartSubclass extends WorldPart then either var myPart:WorldPart = new SomeWorldPartSubclass(); or var myPart:IWorldPart = new SomeWorldPartSubclass(); should both work... HTH, Ian On 2/1/06, j.c.wichman [EMAIL PROTECTED] wrote: Hi, i'm using a collection, which requires items of type Object to be added. I've declared an interface which gives me something like: - interface IWorldPart - a class implementing WorldPart now somewhere else i do: var myPart:IWorldPart = new SomeWorldPartSubclass(); myCollection.addItem (myPart); The last statement gives a type error, if i replace the first with var myPart:WorldPart = new ... all goes well. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] interfaces and objects
Well, you can't instanciate an interface, you need first a concrete class that implements the interface... Your code should be: interface IWorldPart {} class SomeWorldPartSubclass implements IWorldPart {} var myPart:SomeWorldPartSubclass = new SomeWorldPartSubclass(); myCollection.addItem(myPart); j.c.wichman a écrit : Hi, i'm using a collection, which requires items of type Object to be added. I've declared an interface which gives me something like: - interface IWorldPart - a class implementing WorldPart now somewhere else i do: var myPart:IWorldPart = new SomeWorldPartSubclass(); myCollection.addItem (myPart); The last statement gives a type error, if i replace the first with var myPart:WorldPart = new ... all goes well. From what I can remember from Java (which I admit, seems ages ago ;)), this first should be no problem at all. Does anyone know why this is not allowed in Flash? thanks in advance. Hans ___ 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] interfaces and objects
Well, you can't instanciate an interface, you need first a concrete class that implements the interface... While you cannot instantiate an interface, you can assign an object that is an instance of a class that does implement the interface to a variable that is typed to the interface. Your code should be: interface IWorldPart {} class SomeWorldPartSubclass implements IWorldPart {} var myPart:SomeWorldPartSubclass = new SomeWorldPartSubclass(); myCollection.addItem(myPart); I think what the OP is saying is that he wants to do this (based on your example): var myPart:IWorldPart = new SomeWorldPartSubclass(); ...which compiles just fine, but the compiler baulks at the following statement... myCollection.addItem(myPart); If I read correctly, the addItem method is expecting one argument of type Object, and the compiler seems to think that an object of type IWorldPart (i.e. of a class implementing the IWorldPart interface) cannot be stored in a variable of type Object. I don't have time to test this, but if this really is the case then it's a compiler bug. -- Steve Webster Head of Development Featurecreep Ltd. www.featurecreep.com 14 Orchard Street, Bristol, BS1 5EH 0117 905 5047 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] interfaces and objects
No, you can't instantiate an interface. But I don't think Hans was doing that. There's no problem with typing: interface IWorldPart {} class SomeWorldPartSubclass implements IWorldPart {} var myPart:IWorldPart = new SomeWorldPartSubclass(); /* Note INTERFACE-typed var, not concrete */ myCollection.addItem(myPart); Works fine for me on a quick test. A sanity check of trace(myPart instanceof Object); //traces true shows that you should be able to use the myPart variable everywhere that an Object is expected. Ian On 2/1/06, Julien Vignali [EMAIL PROTECTED] wrote: Well, you can't instanciate an interface, you need first a concrete class that implements the interface... Your code should be: interface IWorldPart {} class SomeWorldPartSubclass implements IWorldPart {} var myPart:SomeWorldPartSubclass = new SomeWorldPartSubclass(); myCollection.addItem(myPart); ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] interfaces and objects
Hi, No confusion here ;) except maybe for my fuzzy explanation ;). I did: interface IWorldPart class WorldPart implements IWorldPart class SomeWorldPartSubclass extends WorldPart then either var myPart:WorldPart = new SomeWorldPartSubclass(); or var myPart:IWorldPart = new SomeWorldPartSubclass(); As you described, however collection.addItem (myPart) only works in the first case and not in the second. Probably becoz flash thinks IWorldPart is not an object. I changed it to : var myPart:Object = new SomeWorldPartSubclass(); And it works fine (just as var myPart:WorldPart = new SomeWorldPartSubclass();) by the way. Thanks for your comments, H -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: Wednesday, February 01, 2006 12:36 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] interfaces and objects Um... not quite sure what you're up to here - but it sounds like you're getting a bit confused between IWorldPart and WorldPart. What you need is: interface IWorldPart class SomeWorldPartSubclass implements IWorldPart then var myPart:IWorldPart = new SomeWorldPartSubclass(); should be fine. _OR_ interface WorldPart class SomeWorldPartSubclass implements WorldPart then var myPart:WorldPart = new SomeWorldPartSubclass(); Not quite sure why your description mentions both IWorldPart and WorldPart - unless WorldPart implements IWorldPart..? In which case you're looking for: interface IWorldPart class WorldPart implements IWorldPart class SomeWorldPartSubclass extends WorldPart then either var myPart:WorldPart = new SomeWorldPartSubclass(); or var myPart:IWorldPart = new SomeWorldPartSubclass(); should both work... HTH, Ian On 2/1/06, j.c.wichman [EMAIL PROTECTED] wrote: Hi, i'm using a collection, which requires items of type Object to be added. I've declared an interface which gives me something like: - interface IWorldPart - a class implementing WorldPart now somewhere else i do: var myPart:IWorldPart = new SomeWorldPartSubclass(); myCollection.addItem (myPart); The last statement gives a type error, if i replace the first with var myPart:WorldPart = new ... all goes well. ___ 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] interfaces and objects
Hi, I know u can't instantiate an interface, which wasnt what I was trying to do ;), I was declaring a variable to be of type SomeInterface (instantiating it with SomeConcreteClass), which apparently is not regarded by flash then of being of type Object as well. Got it figured out now ;) Thanks H -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Julien Vignali Sent: Wednesday, February 01, 2006 12:49 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] interfaces and objects Well, you can't instanciate an interface, you need first a concrete class that implements the interface... Your code should be: interface IWorldPart {} class SomeWorldPartSubclass implements IWorldPart {} var myPart:SomeWorldPartSubclass = new SomeWorldPartSubclass(); myCollection.addItem(myPart); j.c.wichman a écrit : Hi, i'm using a collection, which requires items of type Object to be added. I've declared an interface which gives me something like: - interface IWorldPart - a class implementing WorldPart now somewhere else i do: var myPart:IWorldPart = new SomeWorldPartSubclass(); myCollection.addItem (myPart); The last statement gives a type error, if i replace the first with var myPart:WorldPart = new ... all goes well. From what I can remember from Java (which I admit, seems ages ago ;)), this first should be no problem at all. Does anyone know why this is not allowed in Flash? thanks in advance. Hans ___ 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] interfaces and objects
Then as Steve says, sounds like a compiler bug. Ian On 2/1/06, j.c.wichman [EMAIL PROTECTED] wrote: Hi, No confusion here ;) except maybe for my fuzzy explanation ;). I did: interface IWorldPart class WorldPart implements IWorldPart class SomeWorldPartSubclass extends WorldPart then either var myPart:WorldPart = new SomeWorldPartSubclass(); or var myPart:IWorldPart = new SomeWorldPartSubclass(); As you described, however collection.addItem (myPart) only works in the first case and not in the second. Probably becoz flash thinks IWorldPart is not an object. I changed it to : var myPart:Object = new SomeWorldPartSubclass(); And it works fine (just as var myPart:WorldPart = new SomeWorldPartSubclass();) by the way. Thanks for your comments, H ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] interfaces and objects
Hi Ian, Which flash version are you using? I had other problems yesterday with extending CollectionImpl due to my flash version (mx 2004), which worked just fine in flash 8. Might be the same in this case. Are you using 7 or 8? Thanks! Hans -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: Wednesday, February 01, 2006 1:05 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] interfaces and objects No, you can't instantiate an interface. But I don't think Hans was doing that. There's no problem with typing: interface IWorldPart {} class SomeWorldPartSubclass implements IWorldPart {} var myPart:IWorldPart = new SomeWorldPartSubclass(); /* Note INTERFACE-typed var, not concrete */ myCollection.addItem(myPart); Works fine for me on a quick test. A sanity check of trace(myPart instanceof Object); //traces true shows that you should be able to use the myPart variable everywhere that an Object is expected. Ian On 2/1/06, Julien Vignali [EMAIL PROTECTED] wrote: Well, you can't instanciate an interface, you need first a concrete class that implements the interface... Your code should be: interface IWorldPart {} class SomeWorldPartSubclass implements IWorldPart {} var myPart:SomeWorldPartSubclass = new SomeWorldPartSubclass(); myCollection.addItem(myPart); ___ 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] interfaces and objects
But it should. :-) Like I said, my quick test of var myPart:SomeInterface=new SomeConcreteImplementingSomeInterface(); trace(myPart instanceof Object); Traces 'true'. Which is what I'd expect. I really don't understand why you're getting an error with myCollection. I know you've solved your immediate problem - but this is niggling at me now... ;-) Ian On 2/1/06, j.c.wichman [EMAIL PROTECTED] wrote: Hi, I know u can't instantiate an interface, which wasn't what I was trying to do ;), I was declaring a variable to be of type SomeInterface (instantiating it with SomeConcreteClass), which apparently is not regarded by flash then of being of type Object as well. Got it figured out now ;) Thanks H ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] interfaces and objects
Yup, sorry it was my mistake... (I read the message too fast) ;-) j.c.wichman a écrit : Hi, I know u can't instantiate an interface, which wasn’t what I was trying to do ;), I was declaring a variable to be of type SomeInterface (instantiating it with SomeConcreteClass), which apparently is not regarded by flash then of being of type Object as well. Got it figured out now ;) Thanks H -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Julien Vignali Sent: Wednesday, February 01, 2006 12:49 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] interfaces and objects Well, you can't instanciate an interface, you need first a concrete class that implements the interface... Your code should be: interface IWorldPart {} class SomeWorldPartSubclass implements IWorldPart {} var myPart:SomeWorldPartSubclass = new SomeWorldPartSubclass(); myCollection.addItem(myPart); j.c.wichman a écrit : Hi, i'm using a collection, which requires items of type Object to be added. I've declared an interface which gives me something like: - interface IWorldPart - a class implementing WorldPart now somewhere else i do: var myPart:IWorldPart = new SomeWorldPartSubclass(); myCollection.addItem (myPart); The last statement gives a type error, if i replace the first with var myPart:WorldPart = new ... all goes well. From what I can remember from Java (which I admit, seems ages ago ;)), this first should be no problem at all. Does anyone know why this is not allowed in Flash? thanks in advance. Hans ___ 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] interfaces and objects
Hi, At me too ;), it's indeed flash 7 compiler bug it seems, it compiles fine in flash 8. Time for me to switch ;). Greetz Hans -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: Wednesday, February 01, 2006 1:22 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] interfaces and objects But it should. :-) Like I said, my quick test of var myPart:SomeInterface=new SomeConcreteImplementingSomeInterface(); trace(myPart instanceof Object); Traces 'true'. Which is what I'd expect. I really don't understand why you're getting an error with myCollection. I know you've solved your immediate problem - but this is niggling at me now... ;-) Ian On 2/1/06, j.c.wichman [EMAIL PROTECTED] wrote: Hi, I know u can't instantiate an interface, which wasn't what I was trying to do ;), I was declaring a variable to be of type SomeInterface (instantiating it with SomeConcreteClass), which apparently is not regarded by flash then of being of type Object as well. Got it figured out now ;) Thanks H ___ 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] interfaces and objects
Hi, Yes steve was completely right about that. Thanks all! H -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: Wednesday, February 01, 2006 1:19 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] interfaces and objects Then as Steve says, sounds like a compiler bug. Ian On 2/1/06, j.c.wichman [EMAIL PROTECTED] wrote: Hi, No confusion here ;) except maybe for my fuzzy explanation ;). I did: interface IWorldPart class WorldPart implements IWorldPart class SomeWorldPartSubclass extends WorldPart then either var myPart:WorldPart = new SomeWorldPartSubclass(); or var myPart:IWorldPart = new SomeWorldPartSubclass(); As you described, however collection.addItem (myPart) only works in the first case and not in the second. Probably becoz flash thinks IWorldPart is not an object. I changed it to : var myPart:Object = new SomeWorldPartSubclass(); And it works fine (just as var myPart:WorldPart = new SomeWorldPartSubclass();) by the way. Thanks for your comments, H ___ 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] interfaces and objects
MX2004 Cheers, Ian On 2/1/06, j.c.wichman [EMAIL PROTECTED] wrote: Hi Ian, Which flash version are you using? I had other problems yesterday with extending CollectionImpl due to my flash version (mx 2004), which worked just fine in flash 8. Might be the same in this case. Are you using 7 or 8? Thanks! Hans ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] interfaces and objects
'Fraid not. One to chalk down to experience, I guess. Oh well. I'm making the move to 8 shortly myself, once this latest crop of projects are out of the way... Ian On 2/1/06, j.c.wichman [EMAIL PROTECTED] wrote: Life is so unfair :) I had to switch to flash 8 to make it go away... My mind finally at piece... And now you tell me that it wasn't mx2004 :), please tell me you are a mac user ;)) Greetz Hans ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders