Groups | Blog | Home
all groups > flash actionscript > march 2004 >

flash actionscript : How add custom properties to built-in objects?


iweiss
3/2/2004 9:48:31 PM
Hi,

I am just migrating a project to Actionscript 2.0 and ran into a problem: In
1.0 I was adding a custom property to XML nodes like that:

myXMLnode.customProp = "hi";

If I do something like this in 2.0 I am getting en error because the property
does not exist in the class. I know how to add custom functions (via
prototype), but how can I add a custom property to the XMLNode class?

I appreciate every help!
Thanks!
Ingo
Laiverd.COM
3/3/2004 12:57:46 AM
You create a class that extends the original class

with

class Yournode extends XMLNode {
var _prop:String;
// constructor
function Yournode(prop) {
_prop = prop;
trace(_prop)
}
public function getProp(){
return _prop;
}
}

In de flash file:
var myNode:Yournode = new Yournode("your prop value");
trace(myNode.getProp());

That should be it basically.

John



--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

iweiss
3/3/2004 3:27:04 PM
Thanks, John!

The problem with this is that typically nodes aren't created with something
like "new customNode()". I can create a custom XML class "customXML" but if I
access nodes within that object, say "myCustomXMLInstance.firstChild", that
would be always be an instance of the standard XMLNode class and thus don't
have the custom property I need.

It's just like you can't subclass MovieClip by something like "new
customMovieClip()" but you need to attach a library symbol that's associated
with that class instead.

I can't really think of a way to get around that right now.
Ingo
Laiverd.COM
3/3/2004 5:44:09 PM
Maybe post the question at the flashcoders mailing list. Some pretty good
people there. I'm only starting with the whole as2 thing and don't trust
myself on this already ;-)

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

AddThis Social Bookmark Button