Did I find an error in the AS3 XML class?

Suppose a few facts:

Livedocs tells us that classes dynamicallow us to add member variables and member functions. We are told that all classes ultimately stem from Objectwhich dynamic, and that classes dynamicshould be explicitly marked as such - inheritance does not extend to dynamism.

An object is a class dynamic. Date is a class final dynamic. XML is a class final dynamic. You can create your own class final dynamic, and he should behave (in terms of the dynamic capabilities) in the same way as XMLand Dateabove. Actually, finalit should not affect the problem at hand, but I include it for accuracy in my comparison with the "problem" XMLclass.

My code is:

public static function setup():void//Object
{
    //Uncomment each in turn to get results:
    //var o:Object = {};
    //var o:MyFinalDynamicClass = new MyFinalDynamicClass();
    //var o:Date = new Date();
    //var o:XML = new XML();

    o.foo = function():String
    {
        return "Works as expected.";
    }

    trace(o.foo());
}

, o:

: Works as expected.

MyFinalDynamicClass: Works as expected.

: Works as expected.

XML: TypeError: Error #1006: value is not a function.

Date, , final dynamic. , - . - XML.

, AS3 Object, , , , - ++, , , , Adobe AS .

: ? ?

P.S. , , XML, XML.

+3
4

. e4x XML-dom . . , XML, , XML <foo>.

e4x , . :

var o:XML = new XML('<document/>');

o.foo = function():String {
    return "Works as expected.";
};

trace(o.toXMLString());

:

<document>
    <foo>function Function() {}</foo>
</document>

Actionscript3, : Proxy. , , , e4x XML.

+2

livedocs, XML Object. , , , XML. , XML. . / XML. :

var foo:XML = <foo><bar /><bar /></foo>;
trace(foo); // Prints <foo><bar /></foo>

foo.bar = <baz />;
trace(foo); // Prints <foo><baz /></foo>

XML- ActionScript XML, , , . XML -, XML (.. ), , , . :

<foo>
  <bar>function Function() {}</bar>
</foo>

, .

+3

, , , , E4X, , , , , .

Adobe Jira : http://bugs.adobe.com/jira/browse/FP

0

I do not think there is a way around this error. you are absolutely right, but at the same point as they would implement the E4X logic without dynamic xml, if it was not dynamic, it would not be capable of E4X functions. at the same time, I think they added this logic to the object so that users do not get confused with methods that XML does not support in such a way that it looks like a dynamic that is not really fully dynamic.

0
source

Source: https://habr.com/ru/post/1774208/


All Articles