Hey Jason and Ekameleon,

Thanks for the reply.

With the old AS2 code i used.. i could "add" extra code to the textfields constructor(without destroying it :D ). This resulted that both textfields by code and the ones put on the stage in the IDE will have an altered constructor.

This was handy.. because some departments here favour to use the scripted onces.. and other to place them on stage in the IDE. And i need to collect all the textfields for my own actions (that was done with code in the new constructor).

So if i use a custom textfield class.. the textfields placed on the stage won't give a signal when they are initialised.
Now... i could make a component to catch both senario's.. but i rather not..

Any other thoughts?

Thanks

Dennis
Isioux


----- Original Message ----- From: "ekameleon" <[EMAIL PROTECTED]>
To: "Flash Coders List" <flashcoders@chattyfig.figleaf.com>
Sent: Wednesday, August 20, 2008 5:37 PM
Subject: Re: [Flashcoders] AS3 replacing Textfield Constructor


Hello :)

In AS2 or AS1 you can't override the TextField class... if you do that you
destroy the native class :)

You must use the prototype hack with the keyword __proto__ to change the
nature of your instances....

Example :

_global.MyTextField = function()
{
   super();
   //
};

MyTextField.prototype.__proto__ = TextField.prototype ;

MyTextField.prototype.myCustomMethod = function() {}

////

var tf:TextField = createTextField("field", 1, 10,10,250,250) ;

// Hack the native instance with your custom class
tf.__proto__ = MyTextField.prototype ; // hack the prototype
MyTextField.call(tf) ; // launch the constructor

Now .. you can create a global function or a class, an helper to simplify
this hack :)

eKA+ :)





2008/8/20 Dennis - I Sioux <[EMAIL PROTECTED]>

Hey Guys,

I'm an experienced AS2 coder but i'm finally starting in AS3 and want to
port a piece of code that alters the Textfield constructor.
I've tried many things.. but think i'm overlooking something.

My original AS2 code was:

// Alter the constructor of the Textfield
var bfrTextField = TextField;
var bfrStyleSheet = TextField.StyleSheet;

_global.TextField = function() {
    super();
    // Do extra code
};
// reattach the stylesheet class
   _global.TextField.StyleSheet = function() {
    super();
};

TextField.prototype = new bfrTextField();
TextField.StyleSheet.prototype = new bfrStyleSheet();
delete bfrTextField;
delete bfrStyleSheet;


Any help would be appreciated.

With kind regards,

Dennis
Isioux
_______________________________________________
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

__________ NOD32 3373 (20080821) Informatie __________

Dit bericht is gecontroleerd door het NOD32 Antivirus Systeem.
http://www.nod32.nl



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to