Skip to main content
Participating Frequently
June 7, 2010
Question

dynamic class & property

  • June 7, 2010
  • 2 replies
  • 993 views

Hi there!

I would like to know, if it is possible to mimic the behavior of XML dynamic class:

var xm:XML =

    <question idAttr="atribute xml">

    </question>;


trace(xm.attributes());

trace("Attributes: "+xm["attributes"]);

xm["attributes"] = {a:"atr1", b:"atr2"}; (in my dynamic class with attributes function, I get ReferenceError: Error #1037)

trace("Attributes: "+xm["attributes"]);

trace(xm.attributes());

So I can call:

     xm.attributes() method which gives me XML attributes

and use

     xm["attributes"] = {a:"atr1", b:"atr2"};

which writes to the "attributes" property and not references the XML class function.

My question:

How can I do the same in my custom dynamic class ?

Gregory

This topic has been closed for replies.

2 replies

MyWebzzAuthor
Participating Frequently
June 7, 2010

OK, sorry for not the most clear explanation.

In brief: I would like to write a dynamic class, that has a public method attributes() and to be able to add in runtime, a property "attributes" to the intance of that class.

So:

public dynamic class XMLObject extends Object

{

     public function attributes():void

     {

          //do anything

     }

}

var o:XMLObject = new XMLObject();

o["attributes"] = {prop:"my object property"}

o.attrubutes() // runs the method

This is somehow done in XML class...

Hope that now it is more clear...

Gregory

kglad
Community Expert
Community Expert
June 7, 2010

never use flash keywords for user-defined properties, methods or variables.

pick some other method name like attributesF()

MyWebzzAuthor
Participating Frequently
June 7, 2010

The thing is that it is not the name that matters...

if I use other name, Fattributes for example, I still can't adress the instance in a way:

o["Fattributes"] = {prop:"my object"}

because o["Fattributes"] points to a method in the class instance.

But this is somehow solved in the XML class, and I wonder how..

kglad
Community Expert
Community Expert
June 7, 2010

what are you trying to do?  add attributes to your xml instance?