What is VO in flex or amfphp?

The way it is. I am receiving XML data, I need to wait until it is parsed and then dispatch an event after the parse is done from my library.

First, is there a way to avoid events in the library in this case?

The alternative I saw was using VO. So what is it and how to make it work.

+1


a source to share


3 answers


If you can use AMFPHP I would highly recommend it. You can define Value Objects (VOs) both on the server and in actionscript. This will allow you to pass strongly typed objects back and forth from client to server. No need to disassemble, use e4x or suffer at all.



VOs are also called DTOs (Data Transfer Objects) which stand out as object oriented design patterns.

+1


a source


If you are getting the result as XML data from flex, I assume you are using and HTTPService which receives the XML, so you access the data in the ResultEvent property of the result.

eg.

private function resultHandler(e:ResultEvent):void{}

      

You will receive your data:

private function resultHandler(e:ResultEvent):void{
   var tempCollection:ArrayCollection = new ArrayCollection();
   tempCollection = e.result.someDataObject as ArrayCollection;
}

      

and this is where you set the data obtained from xml to a file

private function resultHandler(e:ResultEvent):void{
  var tempCollection:ArrayCollection = new ArrayCollection();
  tempCollection = e.result.someDataNode as ArrayCollection;
for each(var item:Object in tempCollection){
  var myVO:VO = new Image();
  myVO.firstProperty = item.firstProperty;
  myVO.secondProperty = item.secondProperty;
  myVOCollection.addItem(myVO);
 }
}

      

The idea is simple ... VO is just a custom object: the class that you create extends Object and has the goal of storing values ​​from an external data source (e.g. xml result). Because you are using a custom class, which is faster than using a dynamic class, and it helps a lot when reading code and debugging (you get data type checking and all).



They can be anything: groceries in a store, photos in a gallery, etc.

In the example, I assumed someDataNode is a node in you xml and myVOCollection, ArrayCollection for your data, etc.

so VO in this case you would be something like:

package{
class VO{

private var _firstProperty:String;
private var _secondProperty:String;

public function VO(firstProp:String=null,secondProp:String=null){
_firstProperty = firstProp;
_secondProperty = secondProperty;
}

public function get firstProperty():String{
return _firstProperty;
}

public function set firstProperty(value:String):void{
_firstProperty = value;
}

public function get secondProperty():String{
return _secondProperty;
}

public function set secondProperty(value:String):void{
_secondProperty = value;
}

}
}

      

Your model class will probably handle loading and parsing the data, and once that's done, it will dispatch an event so that the application can know that the requested data is available.

In as many words as possible, valueobject in flex will be the actioncipt class that represents the data item. Using one facility, mapping a shared object (which comes from an external source) into its actionscript view.

Nothing unusual.

Hope it helps.

0


a source


A VO when used in conjunction with an external object allows data to be passed from one object (in one langauge) to an equivalent object (in another language).

This way, instead of parsing XML, e4x, etc., you could have the flexibility to talk directly to your PHP through a gateway (i.e. ZendAMF, amfPHP, sabreAMF, etc.).

This site has additional information that explains how to do this (setting up RemoteObject). Of course, what George said is okay, you will need to register the class if you plan on doing remote objects.

http://www.brentknigge.com/?q=node/496

Greetings

0


a source







All Articles