List Info

Thread: as2 xml proxy




as2 xml proxy
country flaguser name
Belgium
2007-10-22 10:57:24
Hi List,

I came up with a xml proxy class after reading some blogs on the net about patterns and as3
it works nicely for view - model communications since updating data is out of the question in this relationship

you can use it as like this:

var dataxml:XML = new XML( '<test id="1"><label&gt;hallo world</label><descr>very big world indeed</descr></test>' );
var proxyataProxy = new DataProxy( dataxml );
value = proxy.getLabel();
OR LIKE THIS
value = proxy.label;


import be.netdust.site.data.IData;
import mx.utils.XPathAPI;

dynamic class be.netdust.core.proxy.DataProxy
{
 ; &nbsp;  &nbsp; 
 &nbsp;  public function DataProxy( data ) {
   ;  &nbsp;  _data = data;
&nbsp; &nbsp; }; &nbsp; 
 &nbsp; 
 &nbsp;  public function __resolve( _sProxyCall:String ) { &nbsp; 
 &nbsp;   &nbsp;  if( _sProxyCall.indexOf("get") != -1 ) {
   ;  &nbsp;   &nbsp;  var field:String = _sProxyCall.substr(3).toLowerCase();
&nbsp; &nbsp;  &nbsp;   &nbsp;  var pataProxy = this;
&nbsp; &nbsp;  &nbsp;   &nbsp;  return function() {
   ;  &nbsp;   &nbsp;   &nbsp;  return p["_resolvexml"].apply( p, [field] );
 ; &nbsp;  &nbsp;   &nbsp;  }
   ;  &nbsp;  }
   ;  &nbsp;  else return _resolvexml( _sProxyCall );
 ; &nbsp; };
 ; &nbsp;  &nbsp; 
 &nbsp;  private function _resolvexml( _sProxyCall:String ) {
   ;  &nbsp; 
 &nbsp;   &nbsp;  var _resultset:Array = XPathAPI.selectNodeList( _data.firstChild, "/*/"+_sProxyCall );

&nbsp; &nbsp;  &nbsp;  if( _resultset.length == 0 ) {
   ;  &nbsp;   &nbsp;  throw new Error( "datamodel has no field property called "+ _sProxyCall );
 ; &nbsp;  &nbsp;   &nbsp;  return null;
&nbsp; &nbsp;  &nbsp;  };
 ; &nbsp;  &nbsp;  if( _resultset.length == 1 ) return _resultset[0].firstChild.nodeValue;

 ; &nbsp;  &nbsp;  // create value array from nodelist;
 &nbsp;   &nbsp;  var _valuearray:Array = [];
&nbsp; &nbsp;  &nbsp;  while( _resultset.length ) {
   ;  &nbsp;   &nbsp;  _valuearray.push( _resultset.shift().firstChild.nodeValue );
 ; &nbsp;  &nbsp;  }; &nbsp; 
 &nbsp;   &nbsp;  return _valuearray; &nbsp;   &nbsp; 
 &nbsp;  };
 ; &nbsp;
 &nbsp;  private var _api;
&nbsp; &nbsp; private var _data;
&nbsp;  
};
Re: as2 xml proxy
user name
2007-10-23 03:38:49
Hi there Stefan,
cool stuff...just one thing, thou. The import statement throw an error, for me is
import mx.xpath.XPathAPI;
and not
import mx.utils.XPathAPI;

thnxs for sharing!

regards, goliatone


On 10/22/07, Stefan Vandermeulen < mailnetdust.be"> mailnetdust.be> wrote:
Hi List,

I came up with a xml proxy class after reading some blogs on the net about patterns and as3
it works nicely for view - model communications since updating data is out of the question in this relationship

you can use it as like this:

var dataxml:XML = new XML( '<test id="1">&lt;label>;hallo world</label><descr>very big world indeed</descr></test>9; );
var proxyataProxy = new DataProxy( dataxml );
value = proxy.getLabel();
OR LIKE THIS
value = proxy.label;


import be.netdust.site.data.IData;
import mx.utils.XPathAPI;

dynamic class be.netdust.core.proxy.DataProxy
{
 ; &nbsp;  &nbsp; 
 &nbsp;  public function DataProxy( data ) {
   ;  &nbsp;  _data = data;
&nbsp; &nbsp; }; &nbsp; 
 &nbsp; 
 &nbsp;  public function __resolve( _sProxyCall:String ) { &nbsp; 
 &nbsp;   &nbsp;  if( _sProxyCall.indexOf(&quot;get&quot;) != -1 ) {
   ;  &nbsp;   &nbsp;  var field:String = _sProxyCall.substr(3).toLowerCase();
&nbsp; &nbsp;  &nbsp;   &nbsp;  var pataProxy = this;
&nbsp; &nbsp;  &nbsp;   &nbsp;  return function() {
   ;  &nbsp;   &nbsp;   &nbsp;  return p["_resolvexml&quot;].apply( p, [field] );
 ; &nbsp;  &nbsp;   &nbsp;  }
   ;  &nbsp;  }
   ;  &nbsp;  else return _resolvexml( _sProxyCall );
 ; &nbsp; };
 ; &nbsp;  &nbsp; 
 &nbsp;  private function _resolvexml( _sProxyCall:String ) {
   ;  &nbsp; 
 &nbsp;   &nbsp;  var _resultset:Array = XPathAPI.selectNodeList( _data.firstChild, "/*/&quot;+_sProxyCall );

&nbsp; &nbsp;  &nbsp;  if( _resultset.length == 0 ) {
   ;  &nbsp;   &nbsp;  throw new Error( "datamodel has no field property called "+ _sProxyCall );
 ; &nbsp;  &nbsp;   &nbsp;  return null;
&nbsp; &nbsp;  &nbsp;  };
 ; &nbsp;  &nbsp;  if( _resultset.length == 1 ) return _resultset[0].firstChild.nodeValue;

 ; &nbsp;  &nbsp;  // create value array from nodelist;
 &nbsp;   &nbsp;  var _valuearray:Array = [];
&nbsp; &nbsp;  &nbsp;  while( _resultset.length ) {
   ;  &nbsp;   &nbsp;  _valuearray.push( _resultset.shift().firstChild.nodeValue );
 ; &nbsp;  &nbsp;  }; &nbsp; 
 &nbsp;   &nbsp;  return _valuearray; &nbsp;   &nbsp; 
 &nbsp;  };
 ; &nbsp;
 &nbsp;  private var _api;
&nbsp; &nbsp; private var _data;
&nbsp;  
};

_______________________________________________
Pixlib mailing list
osflash.org">Pixlibosflash.org
http://osflash.org/mailman/listinfo/pixlib_osflash.org




--
Emiliano Burgos
Flash Designer&amp;Developer
burgosemipaginaswebflash.com">burgosemipaginaswebflash.com
www.paginaswebflash.com
Re: as2 xml proxy
country flaguser name
Belgium
2007-10-23 03:52:47
yes, i know, sorry about that :(
i had to change the path of the files because flashdevelop wouldn't import mx.xpath.XPathAPI
does anybody use flashdevelop here? do you have the same problem?

i'm still working on it too, because i want a decent structure for datamodels and xml. this way you don't need to parse the whole file into an object when you load it ( saves some processing... ) but you can access it as it where an object
when i have a decent structure for this i'll post it again with correct imports

grts
s

Emi Burgos schreef:
mail.gmail.com" type="cite">Hi there Stefan,
cool stuff...just one thing, thou. The import statement throw an error, for me is
import mx.xpath.XPathAPI;
and not
import mx.utils.XPathAPI;

thnxs for sharing!

regards, goliatone


On 10/22/07, Stefan Vandermeulen <netdust.be"> mailnetdust.be> wrote:
Hi List,

I came up with a xml proxy class after reading some blogs on the net about patterns and as3
it works nicely for view - model communications since updating data is out of the question in this relationship

you can use it as like this:

var dataxml:XML = new XML( '<test id="1"><label&gt;hallo world</label><descr>very big world indeed</descr></test>' );
var proxyataProxy = new DataProxy( dataxml );
value = proxy.getLabel();
OR LIKE THIS
value = proxy.label;


import be.netdust.site.data.IData;
import mx.utils.XPathAPI;

dynamic class be.netdust.core.proxy.DataProxy
{
 ; &nbsp;  &nbsp; 
 &nbsp;  public function DataProxy( data ) {
   ;  &nbsp;  _data = data;
&nbsp; &nbsp; }; &nbsp; 
 &nbsp; 
 &nbsp;  public function __resolve( _sProxyCall:String ) { &nbsp; 
 &nbsp;   &nbsp;  if( _sProxyCall.indexOf("get") != -1 ) {
   ;  &nbsp;   &nbsp;  var field:String = _sProxyCall.substr(3).toLowerCase();
&nbsp; &nbsp;  &nbsp;   &nbsp;  var pataProxy = this;
&nbsp; &nbsp;  &nbsp;   &nbsp;  return function() {
   ;  &nbsp;   &nbsp;   &nbsp;  return p["_resolvexml"].apply( p, [field] );
 ; &nbsp;  &nbsp;   &nbsp;  }
   ;  &nbsp;  }
   ;  &nbsp;  else return _resolvexml( _sProxyCall );
 ; &nbsp; };
 ; &nbsp;  &nbsp; 
 &nbsp;  private function _resolvexml( _sProxyCall:String ) {
   ;  &nbsp; 
 &nbsp;   &nbsp;  var _resultset:Array = XPathAPI.selectNodeList( _data.firstChild, "/*/"+_sProxyCall );

 &nbsp;   &nbsp;  if( _resultset.length == 0 ) {
   ;  &nbsp;   &nbsp;  throw new Error( "datamodel has no field property called "+ _sProxyCall );
 ; &nbsp;  &nbsp;   &nbsp;  return null;
&nbsp; &nbsp;  &nbsp;  };
 ; &nbsp;  &nbsp;  if( _resultset.length == 1 ) return _resultset[0].firstChild.nodeValue;

 &nbsp;   &nbsp;  // create value array from nodelist;
 &nbsp;   &nbsp;  var _valuearray:Array = [];
&nbsp; &nbsp;  &nbsp;  while( _resultset.length ) {
   ;  &nbsp;   &nbsp;  _valuearray.push( _resultset.shift().firstChild.nodeValue );
 ; &nbsp;  &nbsp;  }; &nbsp; 
 &nbsp;   &nbsp;  return _valuearray; &nbsp;   &nbsp; 
 &nbsp;  };
 ; &nbsp;
 &nbsp;  private var _api;
&nbsp; &nbsp; private var _data;
&nbsp;  
};

_______________________________________________
Pixlib mailing list
osflash.org">Pixlibosflash.org
http://osflash.org/mailman/listinfo/pixlib_osflash.org




--
Emiliano Burgos
Flash Designer&amp;Developer
paginaswebflash.com">burgosemipaginaswebflash.com
www.paginaswebflash.com

_______________________________________________ Pixlib mailing list osflash.org">Pixlibosflash.org http://osflash.org/mailman/listinfo/pixlib_osflash.org __________ NOD32 2608 (20071023) Informatie __________ Dit bericht is gecontroleerd door het NOD32 Antivirus Systeem. http://www.nod32.nl

Re: as2 xml proxy
user name
2007-10-23 10:24:55
Great stuff,
i will be playing a bit with it...btw, i use Flashdevelop and i do get the same error...

On 10/23/07, Stefan Vandermeulen < mailnetdust.be"> mailnetdust.be> wrote:
ok, i finished a structure for datamodels (attachment) using xml.I hope it&#39;s useful for some and maybe you can comment on it? make it better or maybe there are better ways to achieve this in as2.
the whole idea is not to parse the xml onload, but use it as an object anyway! making it easy to build models and let views communicate with it ( eventually )

grtz
stefan

Stefan Vandermeulen schreef:
yes, i know, sorry about that :(
i had to change the path of the files because flashdevelop wouldn';t import mx.xpath.XPathAPI
does anybody use flashdevelop here? do you have the same problem?

i'm still working on it too, because i want a decent structure for datamodels and xml. this way you don't need to parse the whole file into an object when you load it ( saves some processing... ) but you can access it as it where an object
when i have a decent structure for this i'll post it again with correct imports

grts
s

Emi Burgos schreef:
Hi there Stefan,
cool stuff...just one thing, thou. The import statement throw an error, for me is
import mx.xpath.XPathAPI;
and not
import mx.utils.XPathAPI;

thnxs for sharing!

regards, goliatone


On 10/22/07, Stefan Vandermeulen < mailnetdust.be" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> mailnetdust.be> wrote:
Hi List,

I came up with a xml proxy class after reading some blogs on the net about patterns and as3
it works nicely for view - model communications since updating data is out of the question in this relationship

you can use it as like this:

var dataxml:XML = new XML( '<test id="1">&lt;label>;hallo world</label><descr>very big world indeed</descr></test>9; );
var proxyataProxy = new DataProxy( dataxml );
value = proxy.getLabel();
OR LIKE THIS
value = proxy.label;


import be.netdust.site.data.IData;
import mx.utils.XPathAPI;

dynamic class be.netdust.core.proxy.DataProxy
{
 ; &nbsp;  &nbsp; 
 &nbsp;  public function DataProxy( data ) {
   ;  &nbsp;  _data = data;
&nbsp; &nbsp; }; &nbsp; 
 &nbsp; 
 &nbsp;  public function __resolve( _sProxyCall:String ) { &nbsp; 
 &nbsp;   &nbsp;  if( _sProxyCall.indexOf(&quot;get&quot;) != -1 ) {
   ;  &nbsp;   &nbsp;  var field:String = _sProxyCall.substr(3).toLowerCase();
&nbsp; &nbsp;  &nbsp;   &nbsp;  var pataProxy = this;
&nbsp; &nbsp;  &nbsp;   &nbsp;  return function() {
   ;  &nbsp;   &nbsp;   &nbsp;  return p["_resolvexml&quot;].apply( p, [field] );
 ; &nbsp;  &nbsp;   &nbsp;  }
   ;  &nbsp;  }
   ;  &nbsp;  else return _resolvexml( _sProxyCall );
 ; &nbsp; };
 ; &nbsp;  &nbsp; 
 &nbsp;  private function _resolvexml( _sProxyCall:String ) {
   ;  &nbsp; 
 &nbsp;   &nbsp;  var _resultset:Array = XPathAPI.selectNodeList( _data.firstChild, "/*/&quot;+_sProxyCall );

 &nbsp;   &nbsp;  if( _resultset.length == 0 ) {
   ;  &nbsp;   &nbsp;  throw new Error( "datamodel has no field property called "+ _sProxyCall );
 ; &nbsp;  &nbsp;   &nbsp;  return null;
&nbsp; &nbsp;  &nbsp;  };
 ; &nbsp;  &nbsp;  if( _resultset.length == 1 ) return _resultset[0].firstChild.nodeValue;

 &nbsp;   &nbsp;  // create value array from nodelist;
 &nbsp;   &nbsp;  var _valuearray:Array = [];
&nbsp; &nbsp;  &nbsp;  while( _resultset.length ) {
   ;  &nbsp;   &nbsp;  _valuearray.push( _resultset.shift().firstChild.nodeValue );
 ; &nbsp;  &nbsp;  }; &nbsp; 
 &nbsp;   &nbsp;  return _valuearray; &nbsp;   &nbsp; 
 &nbsp;  };
 ; &nbsp;
 &nbsp;  private var _api;
&nbsp; &nbsp; private var _data;
&nbsp;  
};

_______________________________________________
Pixlib mailing list
Pixlibosflash.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Pixlibosflash.org
http://osflash.org/mailman/listinfo/pixlib_osflash.org




--
Emiliano Burgos
Flash Designer&amp;Developer
burgosemipaginaswebflash.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">burgosemipaginaswebflash.com
www.paginaswebflash.com

_______________________________________________
Pixlib mailing list
Pixlibosflash.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Pixlibosflash.org http://osflash.org/mailman/listinfo/pixlib_osflash.org __________ NOD32 2608 (20071023) Informatie __________ Dit bericht is gecontroleerd door het NOD32 Antivirus Systeem. http://www.nod32.nl



__________ NOD32 2608 (20071023) Informatie __________

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

_______________________________________________
Pixlib mailing list
Pixlibosflash.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Pixlibosflash.org http://osflash.org/mailman/listinfo/pixlib_osflash.org __________ NOD32 2608 (20071023) Informatie __________ Dit bericht is gecontroleerd door het NOD32 Antivirus Systeem. http://www.nod32.nl


_______________________________________________
Pixlib mailing list
osflash.org">Pixlibosflash.org
http://osflash.org/mailman/listinfo/pixlib_osflash.org





--
Emiliano Burgos
Flash Designer&amp;Developer
burgosemipaginaswebflash.com"> burgosemipaginaswebflash.com
www.paginaswebflash.com
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )