Re: [Flashcoders] Can I assign a Class to the main timeline?

2006-07-21 Thread JulianG

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?

2006-07-21 Thread Weyert de Boer

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?

2006-07-21 Thread Mark Winterhalder

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?

2006-07-21 Thread janosch

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?

2006-07-21 Thread Weyert de Boer

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


[Flashcoders] Can I assign a Class to the main timeline?

2006-07-20 Thread JulianG

Hello guys:

I'm new to the list.
I've been using Flash for several years now, and I'm coding in AS2 since 
last year. I can create Classes with no problems. I usually extend my 
classes and other original Flash classes.
I usually extend the MovieClip class and assign the class to a Symbol in 
the Library using the Linkage dialog box.
So, most of my MovieClips instead of having code on a keyframe, they 
have a class assigned to them.


Now the question is.. is there a way I can do the same, but with the 
main Timeline?
I mean, I want my main timeline (which already supports all the members 
[properties and methods] of the MovieClip class ) to behave according to 
a certain Class that I write and that is an extension of the MovieClip 
class.
Is this possible? where can I tell flash to associate a certain Class to 
the main timeline instead of a Symbol on the Library?

Any documentation on this?

Thanks in advance!

JulianG

___
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?

2006-07-20 Thread Weyert de Boer
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?

2006-07-20 Thread Patrick Matte

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 flashcoders@chattyfig.figleaf.com
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