Re: [Flashcoders] AS2: generating new instances dynamically?
This discussion is very interesting, so I would like to offer my approach of attaching/construction of visual classes. I am open for optimization hints. I am using something like this: 1) THE CLASS EXTENDING MOVIECLIP class com.path.MyVisual extends MovieClip { public static var _SYMBOL_NAME:String = __Packages.com.path.MyVisual; public static var _SYMBOL_OWNER:Function = MyVisual; public static var _SYMBOL_LINKED = Object.registerClass(_SYMBOL_NAME,_SYMBOL_OWNER); private var __width:Number; private var __text:String; public static function create(target:MovieClip, initObject:Object, depth:Number, name:String):MyVisual { depth = (depth!=undefined?depth:target.getNextHighestDepth()); name = (name!=undefined?name:myVisual+depth); return MyVisual(target.attachMovie(MyVisual._SYMBOL_NAME, name, depth, initObject)); } public static function createInitObject(width:Number, text:String):Object { return { __width: width, __text: text}; } private function MyVisual() { // I can use __width and __text here, if I like so. } } 2) THE CONSTRUCTION OF AN INSTANCE I use the static create/createInitObject methods. The latter gives me its signature when the editor supports code completion. This way, it feels like a constructor and I get the correct type returned: var mv:MyVisual = MyVisual.create(this, MyVisual.createInitObject(200, Hello World)); Have fun, Matthias ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS2: generating new instances dynamically?
To be honest, I've always found that alot of hassle just to attach a movieclip. I've never bought into the createClassObject/createObject-way used by the v2 component framework either. If all you're after is the correct type when using attachMovie, do the following. private var customClip:CustomClip private function onLoad() { var mc:CustomClip = CustomClip(this.attachMovie(CustomClip, customClip, this.getNextHighestDepth())); // calling non-existing method - throws error mc.someMethod(); } Doesn't get any easier than that if you ask me. Of course, in AS3 attachMovie is gone and we can just use: var mc:CustomClip = new CustomClip(); ;-) regards, Muzak - Original Message - From: Matthias Dittgen [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Thursday, May 03, 2007 9:43 AM Subject: Re: [Flashcoders] AS2: generating new instances dynamically? This discussion is very interesting, so I would like to offer my approach of attaching/construction of visual classes. I am open for optimization hints. I am using something like this: 1) THE CLASS EXTENDING MOVIECLIP class com.path.MyVisual extends MovieClip { public static var _SYMBOL_NAME:String = __Packages.com.path.MyVisual; public static var _SYMBOL_OWNER:Function = MyVisual; public static var _SYMBOL_LINKED = Object.registerClass(_SYMBOL_NAME,_SYMBOL_OWNER); private var __width:Number; private var __text:String; public static function create(target:MovieClip, initObject:Object, depth:Number, name:String):MyVisual { depth = (depth!=undefined?depth:target.getNextHighestDepth()); name = (name!=undefined?name:myVisual+depth); return MyVisual(target.attachMovie(MyVisual._SYMBOL_NAME, name, depth, initObject)); } public static function createInitObject(width:Number, text:String):Object { return { __width: width, __text: text}; } private function MyVisual() { // I can use __width and __text here, if I like so. } } 2) THE CONSTRUCTION OF AN INSTANCE I use the static create/createInitObject methods. The latter gives me its signature when the editor supports code completion. This way, it feels like a constructor and I get the correct type returned: var mv:MyVisual = MyVisual.create(this, MyVisual.createInitObject(200, Hello World)); Have fun, Matthias ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: Re: [Flashcoders] AS2: generating new instances dynamically?
Yup. Since I'm working in the Flash IDE, I don't see why I shouldn't. - Original Message - From: Joe Wheeler [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com; 'Muzak' [EMAIL PROTECTED] Sent: Thursday, May 03, 2007 11:28 AM Subject: Re: Re: [Flashcoders] AS2: generating new instances dynamically? I guess you're also attaching the class via the library? ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS2: generating new instances dynamically?
I associate my AS2 classes to my library symbols through Object.registerClass(LibraryID, ClassName). Where: LibraryID is an identifier in the FLA of a movie clip. ClassName is a class that eventually extends a Movieclip. I have a RegisterClasses singleton that is the first thing that is called before I start my application manager. I just change the code in RegisterClasses if I have a different version of a particular class and if I compile with MTASC I don't have to open up the FLA. When attaching a movie clip I just use the attachMovie method and if I wanted to pass arguments to the constructor I would use the 4th argument and pass an object. The object members are equivalent to members of the class. For example passing {something:value} in the method gives the class a member called something when the constructor hits. Just wanted to add my way too! Ciao, Rob. Muzak wrote: To be honest, I've always found that alot of hassle just to attach a movieclip. I've never bought into the createClassObject/createObject-way used by the v2 component framework either. If all you're after is the correct type when using attachMovie, do the following. private var customClip:CustomClip private function onLoad() { var mc:CustomClip = CustomClip(this.attachMovie(CustomClip, customClip, this.getNextHighestDepth())); // calling non-existing method - throws error mc.someMethod(); } Doesn't get any easier than that if you ask me. Of course, in AS3 attachMovie is gone and we can just use: var mc:CustomClip = new CustomClip(); ;-) regards, Muzak - Original Message - From: Matthias Dittgen [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Thursday, May 03, 2007 9:43 AM Subject: Re: [Flashcoders] AS2: generating new instances dynamically? This discussion is very interesting, so I would like to offer my approach of attaching/construction of visual classes. I am open for optimization hints. I am using something like this: 1) THE CLASS EXTENDING MOVIECLIP class com.path.MyVisual extends MovieClip { public static var _SYMBOL_NAME:String = __Packages.com.path.MyVisual; public static var _SYMBOL_OWNER:Function = MyVisual; public static var _SYMBOL_LINKED = Object.registerClass(_SYMBOL_NAME,_SYMBOL_OWNER); private var __width:Number; private var __text:String; public static function create(target:MovieClip, initObject:Object, depth:Number, name:String):MyVisual { depth = (depth!=undefined?depth:target.getNextHighestDepth()); name = (name!=undefined?name:myVisual+depth); return MyVisual(target.attachMovie(MyVisual._SYMBOL_NAME, name, depth, initObject)); } public static function createInitObject(width:Number, text:String):Object { return { __width: width, __text: text}; } private function MyVisual() { // I can use __width and __text here, if I like so. } } 2) THE CONSTRUCTION OF AN INSTANCE I use the static create/createInitObject methods. The latter gives me its signature when the editor supports code completion. This way, it feels like a constructor and I get the correct type returned: var mv:MyVisual = MyVisual.create(this, MyVisual.createInitObject(200, Hello World)); Have fun, Matthias ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS2: generating new instances dynamically?
You can assign values to private and/or public variables of the class using the 4th argument of attachMovie. Just read the API documentation: public attachMovie(id:String, name:String, depth:Number, [initObject:Object]) : MovieClip initObject can be predefined or used on the fly, which looks like: _root.attachMovie(libraryID, instanceName, depth, {myString: Hello World, _x: 20}); This is not the same as using params in the constructor, but these variables are set before the constructor is called, so you can use the values within the constructor, which is nearly the same and works fine for me. hth, Matthias 2007/5/2, sebastian chedal [EMAIL PROTECTED]: If it is a movie clip you want to instantiate then you have to use: _root.attachMovie(libraryID, instanceName, depth); The class associated with it will construct and the onLoad event will trigger if it is being listened to. this indeed works, but then i can't pass any values to the constructor. Is there any way to attachMovie and at the same time pass values to it? I supose I can always refer to it afterwards on the time line and call a custom function... but it would be nice to use the constructor's functionality. I had hoped I could generate new instances just by calling a constructor instead of attaching it to something; but i guess logically i it needs to be attached to be on the timeline. Correct me if I am wrong. Thanks! Seb. On 5/1/07, O. Fouad [EMAIL PROTECTED] wrote: are u executing the class post view? On 5/1/07, Andy Herrman [EMAIL PROTECTED] wrote: Or have the function return it, which is what it seems like would be the right thing for that method. -Andy On 5/1/07, Ron Wheeler [EMAIL PROTECTED] wrote: I am not sure if you are showing all the code but in your code fragment, newPost is a local variable that will be destroyed as soon as createPost ends. A short and brutal life. It needs to be a class property and you will want to have a getter to access it. Ron sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them and attach them to _root [or some other MC in the timeline]. Thanks!! Seb. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- O.Fouad - Digital Emotions ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your
Re: [Flashcoders] AS2: generating new instances dynamically?
Please Sebastian, show all code in the next post. regards. -- Leandro Amano Digital Bug Chief Creative Officer Adobe Certified Expert Adobe Certified Instructor Adobe User Group Leader On 5/2/07, Matthias Dittgen [EMAIL PROTECTED] wrote: You can assign values to private and/or public variables of the class using the 4th argument of attachMovie. Just read the API documentation: public attachMovie(id:String, name:String, depth:Number, [initObject:Object]) : MovieClip initObject can be predefined or used on the fly, which looks like: _root.attachMovie(libraryID, instanceName, depth, {myString: Hello World, _x: 20}); This is not the same as using params in the constructor, but these variables are set before the constructor is called, so you can use the values within the constructor, which is nearly the same and works fine for me. hth, Matthias ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS2: generating new instances dynamically?
Hi Sebastian, When extending the MovieClip Class in AS2, there is no way to access the constructor. All initializations should be done, like Matthias Dittgen mentionned with the optional initObject argument of attachMovie(libraryID, instanceName, depth, initObject) That way you set all the properties that you need before the onLoad() of your Class. Don't forget that it's a MovieClip and in AS2 it's instances are not handled the same way as other Classes and has it's own rules :) You should read on the MovieClip Class, it's all there HTH Alain sebastian chedal wrote: If it is a movie clip you want to instantiate then you have to use: _root.attachMovie(libraryID, instanceName, depth); The class associated with it will construct and the onLoad event will trigger if it is being listened to. this indeed works, but then i can't pass any values to the constructor. Is there any way to attachMovie and at the same time pass values to it? I supose I can always refer to it afterwards on the time line and call a custom function... but it would be nice to use the constructor's functionality. I had hoped I could generate new instances just by calling a constructor instead of attaching it to something; but i guess logically i it needs to be attached to be on the timeline. Correct me if I am wrong. Thanks! Seb. On 5/1/07, O. Fouad [EMAIL PROTECTED] wrote: are u executing the class post view? On 5/1/07, Andy Herrman [EMAIL PROTECTED] wrote: Or have the function return it, which is what it seems like would be the right thing for that method. -Andy On 5/1/07, Ron Wheeler [EMAIL PROTECTED] wrote: I am not sure if you are showing all the code but in your code fragment, newPost is a local variable that will be destroyed as soon as createPost ends. A short and brutal life. It needs to be a class property and you will want to have a getter to access it. Ron sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them and attach them to _root [or some other MC in the timeline]. Thanks!! Seb. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- O.Fouad - Digital Emotions ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and
RE: [Flashcoders] AS2: generating new instances dynamically?
Another way to do this is to have an init() method that you call in-line to your attachMovie(). class MyClass extends MovieClip { public function MyClass() {} public function init(args):MyClass { // do your constructor type stuff here return this } } And this is how you use it: var myClass:MyClass = myClip.attachMovie(linkage, name, depth).init(args); This way, you can also type-cast your instance to your Class without having to re-cast. I forgot who came up with this or where I saw it, but it's been pretty useful for me when extending MovieClip. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Wednesday, May 02, 2007 9:08 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] AS2: generating new instances dynamically? Hi Sebastian, When extending the MovieClip Class in AS2, there is no way to access the constructor. All initializations should be done, like Matthias Dittgen mentionned with the optional initObject argument of attachMovie(libraryID, instanceName, depth, initObject) That way you set all the properties that you need before the onLoad() of your Class. Don't forget that it's a MovieClip and in AS2 it's instances are not handled the same way as other Classes and has it's own rules :) You should read on the MovieClip Class, it's all there HTH Alain sebastian chedal wrote: If it is a movie clip you want to instantiate then you have to use: _root.attachMovie(libraryID, instanceName, depth); The class associated with it will construct and the onLoad event will trigger if it is being listened to. this indeed works, but then i can't pass any values to the constructor. Is there any way to attachMovie and at the same time pass values to it? I supose I can always refer to it afterwards on the time line and call a custom function... but it would be nice to use the constructor's functionality. I had hoped I could generate new instances just by calling a constructor instead of attaching it to something; but i guess logically i it needs to be attached to be on the timeline. Correct me if I am wrong. Thanks! Seb. On 5/1/07, O. Fouad [EMAIL PROTECTED] wrote: are u executing the class post view? On 5/1/07, Andy Herrman [EMAIL PROTECTED] wrote: Or have the function return it, which is what it seems like would be the right thing for that method. -Andy On 5/1/07, Ron Wheeler [EMAIL PROTECTED] wrote: I am not sure if you are showing all the code but in your code fragment, newPost is a local variable that will be destroyed as soon as createPost ends. A short and brutal life. It needs to be a class property and you will want to have a getter to access it. Ron sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them and attach them to _root [or some other MC in the timeline]. Thanks!! Seb. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS2: generating new instances dynamically?
You might want to consider using composition. class Sample { private var self:MovieClip; function Sample(clip:MovieClip) { self = clip; } } Usage: mySample = new Sample(this.attachMovie(id, instance, depth)); Composition has many advantages over extending MovieClip. I'm not saying you should always use it over linked classes, but it definitely comes in handy for stuff like this. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] AS2: generating new instances dynamically?
var myClass:MyClass = myClip.attachMovie(linkage, name, depth).init(args); That code will fire an error like this : Type mismatch in assignment statement: found MovieClip where MyClass is required. If you want to typecast your movieclip, I think you need to do : var mc:MovieClip = myClip.attachMovie(linkage, name, depth).init(args); var myClass:MyClass = MyClass(mc); myClass.init(args); BLITZ | Patrick Matte - 310-551-0200 x214 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Ngo Sent: Wednesday, May 02, 2007 6:17 PM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] AS2: generating new instances dynamically? Another way to do this is to have an init() method that you call in-line to your attachMovie(). class MyClass extends MovieClip { public function MyClass() {} public function init(args):MyClass { // do your constructor type stuff here return this } } And this is how you use it: var myClass:MyClass = myClip.attachMovie(linkage, name, depth).init(args); This way, you can also type-cast your instance to your Class without having to re-cast. I forgot who came up with this or where I saw it, but it's been pretty useful for me when extending MovieClip. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Wednesday, May 02, 2007 9:08 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] AS2: generating new instances dynamically? Hi Sebastian, When extending the MovieClip Class in AS2, there is no way to access the constructor. All initializations should be done, like Matthias Dittgen mentionned with the optional initObject argument of attachMovie(libraryID, instanceName, depth, initObject) That way you set all the properties that you need before the onLoad() of your Class. Don't forget that it's a MovieClip and in AS2 it's instances are not handled the same way as other Classes and has it's own rules :) You should read on the MovieClip Class, it's all there HTH Alain sebastian chedal wrote: If it is a movie clip you want to instantiate then you have to use: _root.attachMovie(libraryID, instanceName, depth); The class associated with it will construct and the onLoad event will trigger if it is being listened to. this indeed works, but then i can't pass any values to the constructor. Is there any way to attachMovie and at the same time pass values to it? I supose I can always refer to it afterwards on the time line and call a custom function... but it would be nice to use the constructor's functionality. I had hoped I could generate new instances just by calling a constructor instead of attaching it to something; but i guess logically i it needs to be attached to be on the timeline. Correct me if I am wrong. Thanks! Seb. On 5/1/07, O. Fouad [EMAIL PROTECTED] wrote: are u executing the class post view? On 5/1/07, Andy Herrman [EMAIL PROTECTED] wrote: Or have the function return it, which is what it seems like would be the right thing for that method. -Andy On 5/1/07, Ron Wheeler [EMAIL PROTECTED] wrote: I am not sure if you are showing all the code but in your code fragment, newPost is a local variable that will be destroyed as soon as createPost ends. A short and brutal life. It needs to be a class property and you will want to have a getter to access it. Ron sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them and attach them to _root [or some other MC in the timeline]. Thanks!! Seb. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] AS2: generating new instances dynamically?
Are you sure you're implementing it correctly? You have to assign the class to your library item and it should work. If you're just arbitrarily attaching a MovieClip from the library without assigning that symbol the class, it will give you that error. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Patrick Matte | BLITZ Sent: Wednesday, May 02, 2007 10:20 PM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] AS2: generating new instances dynamically? var myClass:MyClass = myClip.attachMovie(linkage, name, depth).init(args); That code will fire an error like this : Type mismatch in assignment statement: found MovieClip where MyClass is required. If you want to typecast your movieclip, I think you need to do : var mc:MovieClip = myClip.attachMovie(linkage, name, depth).init(args); var myClass:MyClass = MyClass(mc); myClass.init(args); BLITZ | Patrick Matte - 310-551-0200 x214 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Ngo Sent: Wednesday, May 02, 2007 6:17 PM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] AS2: generating new instances dynamically? Another way to do this is to have an init() method that you call in-line to your attachMovie(). class MyClass extends MovieClip { public function MyClass() {} public function init(args):MyClass { // do your constructor type stuff here return this } } And this is how you use it: var myClass:MyClass = myClip.attachMovie(linkage, name, depth).init(args); This way, you can also type-cast your instance to your Class without having to re-cast. I forgot who came up with this or where I saw it, but it's been pretty useful for me when extending MovieClip. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Wednesday, May 02, 2007 9:08 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] AS2: generating new instances dynamically? Hi Sebastian, When extending the MovieClip Class in AS2, there is no way to access the constructor. All initializations should be done, like Matthias Dittgen mentionned with the optional initObject argument of attachMovie(libraryID, instanceName, depth, initObject) That way you set all the properties that you need before the onLoad() of your Class. Don't forget that it's a MovieClip and in AS2 it's instances are not handled the same way as other Classes and has it's own rules :) You should read on the MovieClip Class, it's all there HTH Alain sebastian chedal wrote: If it is a movie clip you want to instantiate then you have to use: _root.attachMovie(libraryID, instanceName, depth); The class associated with it will construct and the onLoad event will trigger if it is being listened to. this indeed works, but then i can't pass any values to the constructor. Is there any way to attachMovie and at the same time pass values to it? I supose I can always refer to it afterwards on the time line and call a custom function... but it would be nice to use the constructor's functionality. I had hoped I could generate new instances just by calling a constructor instead of attaching it to something; but i guess logically i it needs to be attached to be on the timeline. Correct me if I am wrong. Thanks! Seb. On 5/1/07, O. Fouad [EMAIL PROTECTED] wrote: are u executing the class post view? On 5/1/07, Andy Herrman [EMAIL PROTECTED] wrote: Or have the function return it, which is what it seems like would be the right thing for that method. -Andy On 5/1/07, Ron Wheeler [EMAIL PROTECTED] wrote: I am not sure if you are showing all the code but in your code fragment, newPost is a local variable that will be destroyed as soon as createPost ends. A short and brutal life. It needs to be a class property and you will want to have a getter to access it. Ron sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them
Re: [Flashcoders] AS2: generating new instances dynamically?
If it is a movie clip you want to instantiate then you have to use: _root.attachMovie(libraryID, instanceName, depth); The class associated with it will construct and the onLoad event will trigger if it is being listened to. Ciao, Rob. sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them and attach them to _root [or some other MC in the timeline]. Thanks!! Seb. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS2: generating new instances dynamically?
I am not sure if you are showing all the code but in your code fragment, newPost is a local variable that will be destroyed as soon as createPost ends. A short and brutal life. It needs to be a class property and you will want to have a getter to access it. Ron sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them and attach them to _root [or some other MC in the timeline]. Thanks!! Seb. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS2: generating new instances dynamically?
Or have the function return it, which is what it seems like would be the right thing for that method. -Andy On 5/1/07, Ron Wheeler [EMAIL PROTECTED] wrote: I am not sure if you are showing all the code but in your code fragment, newPost is a local variable that will be destroyed as soon as createPost ends. A short and brutal life. It needs to be a class property and you will want to have a getter to access it. Ron sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them and attach them to _root [or some other MC in the timeline]. Thanks!! Seb. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] AS2: generating new instances dynamically?
are u executing the class post view? On 5/1/07, Andy Herrman [EMAIL PROTECTED] wrote: Or have the function return it, which is what it seems like would be the right thing for that method. -Andy On 5/1/07, Ron Wheeler [EMAIL PROTECTED] wrote: I am not sure if you are showing all the code but in your code fragment, newPost is a local variable that will be destroyed as soon as createPost ends. A short and brutal life. It needs to be a class property and you will want to have a getter to access it. Ron sebastian chedal wrote: Hello Flashcoders, Sorry to bother you with another simple AS2 questions, I'm making good progress but I am stumped with one simple thing. I have one class/object that I want to use to generate copies [instances] of another class. The second class is an object in the library with an ID and an assosiated *.as file [in the linkage panel]. The code is: = //PostModel.as import com.blabla.PostView; class com.blabla.PostModel { public function createPost (__id) { var newPost = new PostView (__id); } } = When I run this code, the class doesn't construct an instance... What am I missing? If I need to call the Library Identifyer instead, how would I do that? I don't want to attach the PostView to the PostModel class, I just want to create instances of them and attach them to _root [or some other MC in the timeline]. Thanks!! Seb. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- O.Fouad - Digital Emotions ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com