Re: [Flashcoders] Can I assign a Class to the main timeline?
You might want to try this, below the contructor of the Application-class. This will be come the class associated with the main class. Seems to work for me. /** * Constructor * * @paramtimelineThe timeline */ public function Application( target ) { super(); // target.__proto__ = __proto__; target.__constructor__ = com.Application( com.Application ); this = com.Application( target ); com.Application( target ); } ___ 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] Can I assign a Class to the main timeline?
Nice trick. But this seems to work as well but simpler. class com.Application{ public function Application( target ) { target.__proto__ = __proto__; this = com.Application( target ); } } - Original Message - From: "Weyert de Boer" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" Sent: Thursday, July 20, 2006 8:31 PM Subject: Re: [Flashcoders] Can I assign a Class to the main timeline? You might want to try this, below the contructor of the Application-class. This will be come the class associated with the main class. Seems to work for me. /** * Constructor * * @paramtimelineThe timeline */ public function Application( target ) { super(); // target.__proto__ = __proto__; target.__constructor__ = com.Application( com.Application ); this = com.Application( target ); com.Application( target ); } ___ 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] Can I assign a Class to the main timeline?
Thanks you Patrick and Weyert! I tried Patrick's approach and it worked. I had never used this __proto__ thing before. Besides this, what do you use __proto__ or "prototype" for? I never use it. Maybe I'm missing something. thanks, JulianG Patrick Matte wrote: Nice trick. But this seems to work as well but simpler. class com.Application{ public function Application( target ) { target.__proto__ = __proto__; this = com.Application( target ); } } ___ 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] Can I assign a Class to the main timeline?
No clue, it just works ;-) ___ 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] Can I assign a Class to the main timeline?
On 7/21/06, JulianG <[EMAIL PROTECTED]> wrote: Thanks you Patrick and Weyert! I tried Patrick's approach and it worked. I had never used this __proto__ thing before. Besides this, what do you use __proto__ or "prototype" for? I never use it. Maybe I'm missing something. __proto__ is a property every object has (except Object.prototype, I guess), pointing ot its prototype. It's the way inheritance works in the Flash VM, the Prototype Chain. Say you have Foo extending Bar. Then any instance myFoo of Foo will have myFoo.__proto__ == Foo.prototype, and Foo.prototype.__proto__ will point to Bar.prototype. Since Bar only inherits from Object, Bar.prototype.__proto__ will point to Object.prototype. Now, when you try to access a property of myFoo, the VM will first check if your instance has it itself. If not, it will check its __proto__, than the __proto__ of the __proto__, and so on, until it eventually ends up at Object.prototype. If that doesn't have it, either, it will call myFoo.__resolve() and pass a string with the identifier of what had been tried to be accessed as an argument, and use what you return as its value. So, if you do...: var myFoo = new Foo(); myFoo.__proto__ = Foobar.prototype; then you modify the inheritance, your myFoo will have all the methods an instance of Foobar would have. Think of how it used to be done in AS1 (still works, BTW). You'd create a class by declaring a constructor function: function Foo () { this.text = "hello world!"; } to inherit from Bar, you'd create a new instance of Bar and assign it as Foo's prototype: Foo.prototype = new Bar(); Some didn't like to instantiate an instance of the parent class to inherit from, so they did this instead (causing lots of interesting discussions whether or not to stick with documented features, as __proto__ was undocumented back then): Foo.prototype.__proto__ = Bar.prototype; To add methods (or properties), you'd attach them to that prototype: Foo.prototype.sayHello = function () { trace( this.text ); }; So, instead of myFoo = new Foo(), you could also do: var myFoo = {}; myFoo.__proto__ = Foo.prototype; myFoo.__constructor__ = Foo; Foo.apply( MyFoo ); Which is precisely what you're doing right now, except for the last line which calls the constructor. HTH, Mark ___ 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] Can I assign a Class to the main timeline?
This is a very nice explenation, thanks! Janosch Mark Winterhalder schrieb: On 7/21/06, JulianG <[EMAIL PROTECTED]> wrote: Thanks you Patrick and Weyert! I tried Patrick's approach and it worked. I had never used this __proto__ thing before. Besides this, what do you use __proto__ or "prototype" for? I never use it. Maybe I'm missing something. __proto__ is a property every object has (except Object.prototype, I guess), pointing ot its prototype. It's the way inheritance works in the Flash VM, the Prototype Chain. Say you have Foo extending Bar. Then any instance myFoo of Foo will have myFoo.__proto__ == Foo.prototype, and Foo.prototype.__proto__ will point to Bar.prototype. Since Bar only inherits from Object, Bar.prototype.__proto__ will point to Object.prototype. Now, when you try to access a property of myFoo, the VM will first check if your instance has it itself. If not, it will check its __proto__, than the __proto__ of the __proto__, and so on, until it eventually ends up at Object.prototype. If that doesn't have it, either, it will call myFoo.__resolve() and pass a string with the identifier of what had been tried to be accessed as an argument, and use what you return as its value. So, if you do...: var myFoo = new Foo(); myFoo.__proto__ = Foobar.prototype; then you modify the inheritance, your myFoo will have all the methods an instance of Foobar would have. Think of how it used to be done in AS1 (still works, BTW). You'd create a class by declaring a constructor function: function Foo () { this.text = "hello world!"; } to inherit from Bar, you'd create a new instance of Bar and assign it as Foo's prototype: Foo.prototype = new Bar(); Some didn't like to instantiate an instance of the parent class to inherit from, so they did this instead (causing lots of interesting discussions whether or not to stick with documented features, as __proto__ was undocumented back then): Foo.prototype.__proto__ = Bar.prototype; To add methods (or properties), you'd attach them to that prototype: Foo.prototype.sayHello = function () { trace( this.text ); }; So, instead of myFoo = new Foo(), you could also do: var myFoo = {}; myFoo.__proto__ = Foo.prototype; myFoo.__constructor__ = Foo; Foo.apply( MyFoo ); Which is precisely what you're doing right now, except for the last line which calls the constructor. HTH, Mark ___ 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] Can I assign a Class to the main timeline?
Thanks! Good explanation :-) ___ 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