Weird flash.xml.XML behavior

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Weird flash.xml.XML behavior

go2ghana
Hi,
The code below traces null 4 target.xml in the addListener method
and I don't get why.
Anyone?

Cordially,
Axel


package ;

import flash.Lib;
import flash.xml.XML;

/**
  * ...
  * @author Axel Huizinga - [hidden email]
  */

class Main
{

     public var xml(getXml, setXml):XML;
     var _xml:XML;

     public function new() { }

     public function setXml(xml:XML ):XML
     {
         trace(xml.toXMLString());
         _xml = xml;
         return xml;
     }

     public function getXml():XML
     {
         return _xml;
     }

     static function main()
     {
         var m:Main = new Main();
         m.xml = new XML('<rect id="test" x="100" y="100" width="300"
height="300" style="fill:red" onclick="test" />');
         var v:Viewer = new Viewer();
         v.addListener('ttt', m);
     }

}

class Viewer
{
     public function new() { }

     public function addListener(type:String, target:Dynamic)
     {
         trace(type + ':' + target.xml);
         //trace(type + ':' + target.xml.toXMLString());
     }
}

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Weird flash.xml.XML behavior

jlm@justinfront.net
I think the issue is that you have typed it as Dynamic rather than  
Main, because you can still access it via getXml.

Cheers

;j

On 29 Jul 2011, at 19:54, Axel Huizinga wrote:

> Hi,
> The code below traces null 4 target.xml in the addListener method
> and I don't get why.
> Anyone?
>
> Cordially,
> Axel
>
>
> package ;
>
> import flash.Lib;
> import flash.xml.XML;
>
> /**
> * ...
> * @author Axel Huizinga - [hidden email]
> */
>
> class Main
> {
>
>    public var xml(getXml, setXml):XML;
>    var _xml:XML;
>
>    public function new() { }
>
>    public function setXml(xml:XML ):XML
>    {
>        trace(xml.toXMLString());
>        _xml = xml;
>        return xml;
>    }
>
>    public function getXml():XML
>    {
>        return _xml;
>    }
>
>    static function main()
>    {
>        var m:Main = new Main();
>        m.xml = new XML('<rect id="test" x="100" y="100" width="300"  
> height="300" style="fill:red" onclick="test" />');
>        var v:Viewer = new Viewer();
>        v.addListener('ttt', m);
>    }
>
> }
>
> class Viewer
> {
>    public function new() { }
>
>    public function addListener(type:String, target:Dynamic)
>    {
>        trace(type + ':' + target.xml);
>        //trace(type + ':' + target.xml.toXMLString());
>    }
> }
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Weird flash.xml.XML behavior

go2ghana
Am 29.07.2011 21:14, schrieb [hidden email]:
> I think the issue is that you have typed it as Dynamic rather than
> Main, because you can still access it via getXml.
>
True - thank for the quick response - though I still not really get why
Dynamic can loose a property?

> Cheers
>
> ;j
>
> On 29 Jul 2011, at 19:54, Axel Huizinga wrote:
>
>> Hi,
>> The code below traces null 4 target.xml in the addListener method
>> and I don't get why.
>> Anyone?
>>
>> Cordially,
>> Axel
>>
>>
>> package ;
>>
>> import flash.Lib;
>> import flash.xml.XML;
>>
>> /**
>> * ...
>> * @author Axel Huizinga - [hidden email]
>> */
>>
>> class Main
>> {
>>
>>    public var xml(getXml, setXml):XML;
>>    var _xml:XML;
>>
>>    public function new() { }
>>
>>    public function setXml(xml:XML ):XML
>>    {
>>        trace(xml.toXMLString());
>>        _xml = xml;
>>        return xml;
>>    }
>>
>>    public function getXml():XML
>>    {
>>        return _xml;
>>    }
>>
>>    static function main()
>>    {
>>        var m:Main = new Main();
>>        m.xml = new XML('<rect id="test" x="100" y="100" width="300"
>> height="300" style="fill:red" onclick="test" />');
>>        var v:Viewer = new Viewer();
>>        v.addListener('ttt', m);
>>    }
>>
>> }
>>
>> class Viewer
>> {
>>    public function new() { }
>>
>>    public function addListener(type:String, target:Dynamic)
>>    {
>>        trace(type + ':' + target.xml);
>>        //trace(type + ':' + target.xml.toXMLString());
>>    }
>> }
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>


--
haXe - an open source web programming language
http://haxe.org