HttpService resultFormat e4x v. object

hi,
anyone have any idea if there is any appreciable performance
difference between using e4x format and object format?
i'm trying to figure out which of these two formats to use
under what circumstances and i believe that performance is one of
the criteria to consider.
subsequent usage intention for the structure is the next
obvious thing to look at, but i need to start somewhere ;)
i'm guessing object format would take more cycles to
accomplish, but hey, what do i know...?
thanks,
tony.

Use e4x.
First, unless you are using RemoteObject, you data is
probably XML already. resultFormat="object", the default, causes
Flex to attempt to convert your xml into an nested object
structure. This is a "black box" behavior. Predicting the output
structure is difficult. This conversion also takes time.
Second, e4x XML has huge functionality built in. You can
search, filter the data efficiently and easily. You will have to
write recursive functions to do that with a nested object
structure.
XML is easily handled in XMLList and XMLListCollection
objects with their methods. With object you have to do it all
yourself.
Finally, AS is very fast. Performance is always a good thing,
but until you are an expert on issues like when to use
cacheAsBitmap, you will be better served focusing on UI rendereing
performance, not machine cycles.
Tracy

Similar Messages

  • [svn] 3075: Restoring the default HTTPService resultFormat to "object" to fix QE tests for HTTPService.

    Revision: 3075
    Author: [email protected]
    Date: 2008-09-03 09:07:35 -0700 (Wed, 03 Sep 2008)
    Log Message:
    Restoring the default HTTPService resultFormat to "object" to fix QE tests for HTTPService.
    QA: Yes, this address .
    Doc: No
    Checkintests: Pass
    Bugs:
    SDK-16706 - httpservice fails to fetch data
    SDK-16696 - accessing parameters via httpservice's result gives runtime exception.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-16706
    http://bugs.adobe.com/jira/browse/SDK-16696
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/rpc/http/AbstractOperation.as

  • Possible memory leak in e4x or HTTPService with e4x format

    Hello,
    I think I have found a memory leak in e4x.
    In very special cases (=xml) the player swallows the memory.
    The little test program connects to a web server for an xml
    file, and the result is converted to an array.
    The array is displayed in a DataGrid.
    There are two files:
    leaktest.xml doesn't leak in any cases (format: e4x or xml)
    pbentries.xml leaks when the format is e4x.
    Choose e4x format and check Use "Leak" file! Than the program
    leaks.
    For the whole test case (mxml file, html file and xml files)
    please contact me at
    [email protected]
    or
    [email protected]
    and I send a zip file as soon as possible.
    Probably there is a bug in my test program. If so than please
    send me a feedback.
    Thanks,
    Lacito
    ------ For the program cut here ------
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import mx.managers.PopUpManager;
    import mx.core.Application;
    import mx.controls.Alert;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.http.mxml.HTTPService;
    protected var records_:Array = null;
    protected var httpService:HTTPService = null;
    [Bindable("recordsChange")]
    public function set records(_records:Array):void
    this.records_ = _records;
    var e:Event = new Event("recordsChange");
    dispatchEvent(e);
    public function get records():Array
    return records_;
    protected function getXML():void
    var resultFormat:String = cbResultFormat.selectedItem as
    String;
    var params:Object = new Object();
    httpService = new HTTPService();
    httpService.concurrency = "single";
    httpService.showBusyCursor = true;
    var lastIndex:int = url.lastIndexOf("/");
    var fileName:String = null;
    if(chbUseLeakFile.selected)
    // It leaks... :(
    fileName = "pbentries.xml";
    else
    // It doesn't leak... :)
    fileName = "leaktest.xml";
    var _url:String = url.substr(0, lastIndex+1) + fileName;
    httpService.url = _url;
    httpService.resultFormat = resultFormat;
    httpService.method = "POST";
    httpService.addEventListener(ResultEvent.RESULT,
    processResult);
    httpService.addEventListener(FaultEvent.FAULT,
    processFault);
    httpService.send(params);
    protected function processResult(e:ResultEvent):void
    var resultFormat:String = cbResultFormat.selectedItem as
    String;
    removeListeners();
    if(resultFormat==mx.rpc.http.HTTPService.RESULT_FORMAT_XML)
    setArrayFromXMLNode();
    else
    setArrayFromXML();
    destroyHttpService();
    // format= "e4x"
    protected function setArrayFromXML():void
    var xml_:XML = httpService.lastResult as XML;
    var ar:Array = new Array();
    var x:XML = null;
    var xl:XMLList = xml_.phonebookEntries[0].phonebookEntry;
    for each(x in xl)
    var record:Object = new Object();
    var prop:XML = null;
    var props:XMLList = x.children();
    for each(prop in props)
    record[prop.localName()] = prop.toString();
    ar.push(record);
    records = ar;
    // format= "xml"
    protected function setArrayFromXMLNode():void
    var xml_:XMLNode = httpService.lastResult as XMLNode;
    var ar:Array = new Array();
    var x:XMLNode = null;
    var xl:Array = xml_.lastChild.childNodes;
    for each(x in xl)
    var record:Object = new Object();
    var prop:XMLNode = null;
    var props:Array = x.childNodes;
    for each(prop in props)
    record[prop.localName] = prop.firstChild!=null ?
    prop.firstChild.nodeValue : null;
    ar.push(record);
    records = ar;
    protected function destroyHttpService():void
    httpService.clearResult(false);
    httpService.disconnect();
    httpService = null;
    protected function processFault(e:FaultEvent):void
    removeListeners();
    Alert.show(e.fault.faultString, e.fault.faultCode);
    destroyHttpService();
    protected function removeListeners():void
    httpService.removeEventListener(ResultEvent.RESULT,
    processResult);
    httpService.removeEventListener(FaultEvent.FAULT,
    processFault);
    protected function collect():void
    // Garbage Collection
    try
    new LocalConnection().connect('foo');
    new LocalConnection().connect('foo');
    catch(e:*)
    ]]>
    </mx:Script>
    <mx:ArrayCollection id="alRecords" source="{records}"
    />
    <mx:Label x="10" y="10" text="Result format:"
    id="lResultFormat"/>
    <mx:ComboBox x="104" y="8" id="cbResultFormat">
    <mx:Array>
    <mx:String>e4x</mx:String>
    <mx:String>xml</mx:String>
    </mx:Array>
    </mx:ComboBox>
    <mx:DataGrid id="dgRecords" x="10" y="36" width="936"
    height="437"
    dataProvider="{alRecords}"
    verticalScrollPolicy="auto"
    horizontalScrollPolicy="auto">
    </mx:DataGrid>
    <mx:Button x="355" y="496" label="Get xml" id="btnGetXML"
    click="{getXML();}" />
    <mx:Button x="155" y="496" label="GC" id="btnGC"
    click="{collect();}" />
    <mx:CheckBox x="276" y="10" label="Use
    &quot;LEAK&quot; file:" labelPlacement="left"
    id="chbUseLeakFile" selected="true"/>
    </mx:Application>

    Hello,
    After 3 months (and a new version of flex and flash player)
    my test program is still leaking.
    If somebody could confirm the leak it would be appreciated.
    Thanks,
    Lacito
    P.S.: I heard that Adobe had donated ActionScript 3 VM to
    Mozilla.org. Should I disturb them with my problem?

  • HTTPService of e4x sending data from an XMLListCollection?

    I'm converting an applicaton to use e4x httpservice calls to get and send variables to a PHP remote service and seems to have run into a few questions I can't find any forums posts or documentation about. Currently the application uses the object model to get data and sends and receives variables
    from the PHP scripts through a bunch of $_POST variables. When pulling stuff into the application it gets stored in an array collection so I can sort it and search it easily using cursors. Here are my questions:
    Getting stuff from an HTTPservice with a type of e4x is easy. works great. I toss it right into an XMLarraycollection and get my sorting. But sending data to the same service setup as a type of 'e4x' I can't figure out. Using the object model I could just send an object of keys and properties so sending a { key : value }, would go to the PHP file as a $_POST['key'] and I could read the value. Since httpservice of e4x enforces the need for a root XML tag, all I seem to get is a $_POST['root'], and none of the real key:value data I need. I'm clearing missing something. So how on the PHP side do I get my values if I have to send this root tag? Or in flex how to I send XMLlists instead of XML.? This has to be possible. I don't want to use a different service just to send.
    Second, and a minor thing. When I do send variables to  and httpservice of e4x from an XML arraycollection, do I just send it in key:value format, or do I need to toString() it? When it gets to the php script after the post would the variable name and value be $_POST['key']=value or $_POST[<key>']=<value>.
    Thanks in advance!  

    hi,
    have you looked at creating a new document with the root tag as parent then inserting the collection, haven't tried this with xmllistcollection but I would think the process is similar to the atraycollection conversion
    var qName:QName = new QName("root");
    var xmlDocument:XMLDocument = new XMLDocument();
    var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
    var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(myArrayCollection.source, qName, xmlDocument);
    trace(xmlDocument.toString());
    David

  • HTTPService using e4x

    I'm trying to use HTTPService to receive xml data from a
    website, using e4x, then put it in a datagrid (and do other things
    with it later). I can get it to populate the datagrid using object,
    but need it in xml form to use it in other places. I've tryed using
    an XMLListCollection, but can't seem to get it working.
    /********************* XML *******************/
    <?xml version="1.0" encoding="iso-8859-1" ?>
    <tool>
    <projects>
    <project>
    <projectName>Project 1</projectName>
    <active>true</active>
    </project>
    <project>
    <projectName>Project 2</projectName>
    <active>true</active>
    </project>
    </projects>
    </tool>
    /***************** This works ****************/
    <mx:HTTPService id="list_request" url="myxml.xml"
    showBusyCursor="true" resultFormat="object"
    fault="Alert.show('Project listing could not be
    retrieved!','Error');"/>
    <mx:DataGrid y="0" width="508" height="291"
    horizontalCenter="0"
    dataProvider="{list_request.lastResult.tool.projects.project}"
    id="dgProjects">
    <mx:columns>
    <mx:DataGridColumn headerText="Projects"
    dataField="projectName"/>
    </mx:columns>
    </mx:DataGrid>
    Thanks in advance.

    Using that I get these console warnings:
    warning: unable to bind to property 'projects' on class 'XML'
    (class is not an IEventDispatcher)
    warning: unable to bind to property 'project' on class
    'XMLList' (class is not an IEventDispatcher)
    Also, I can't figure out why lastResult is returning null if
    I work with it in the same function list_request was called from.
    public function GotoStartPage():void{
    list_request.send();
    // If the query contained a value for project_request...
    if(Application.application.parameters.project_request!=null){
    // Check to see if the query matched one of the listed
    projects
    project_request=Application.application.parameters.project_request;
    currentState="Main Project Page";
    }else{
    trace(list_request.lastResult); // <-
    this gives null
    project_request="";
    currentState="Project Selection Screen";
    Is the trace statement getting called before
    list_request.send() is finished getting the data?

  • Using HTTPService to import data from a XML file

    Hello there!
    I'm having some problem's with this import... If anyone can
    help, I would appreciate it!
    I'm using this type of information as data source:
    public var dataCollection:ArrayCollection =
    new ArrayCollection([
    { id: "P1", name: "Porto", type: "team", children: [
    { id: "R1", name: "Dr Silva", location: "Bloco 1", type:
    "member" },
    { id: "R2", name: "Dra Neto", location: "Gabinete", type:
    "member"
    { id: "P2", name: "Braga", type: "team", children: [
    { id: "R3", name: "Dr Santos", location: "Bloco 2", type:
    "member" },
    { id: "R4", name: "Dra Sonia", location: "Piso 1", type:
    "member"
    But I want to import it from a XML file like this:
    <?xml version="1.0" encoding="utf-8"?>
    <items>
    <item id="P1" name="Porto" type="team">
    <children id="R1" name="Dr Silva" location="Bloco 1"
    type="member" />
    <children id="R2" name="Dra Neto" location="Gabinete"
    type="member" />
    </item>
    <item id="P2" name="Braga" type="team">
    <children id="R3" name="Dr Santos" location="Bloco 2"
    type="member" />
    <children id="R4" name="Dra Sonia" location="Piso 1"
    type="member" />
    </item>
    </items>
    I already import the file, but can not translate the data
    into a array collection.
    private function initApp():void {
    var httpService:HTTPService = new HTTPService();
    httpService.url = "dataprovider.xml";
    httpService.resultFormat = "e4x";
    httpService.addEventListener(FaultEvent.FAULT,
    onFaultHttpService);
    httpService.addEventListener(ResultEvent.RESULT,
    onResultHttpService);
    httpService.send();
    private function onFaultHttpService(e:FaultEvent):void
    Alert.show("Error reading data file.");
    private function onResultHttpService(e:ResultEvent):void
    //Convert the xml data to a array collection
    Thank you

    Hello Peter, and thank you for your reply's.
    My problem is that I'm receiving the data from the external
    file and I don't know how to get the children in place... I mean, I
    also have some data being received form a file that I can convert
    into an array collection, but the thing is, that file doesn't have
    children structure...
    It's something like this:
    <?xml version="1.0" encoding="utf-8"?>
    <items>
    <item id="T1" resourceId="R1" name="Cardiologia"
    startTime="25-3-09 8:0:0" endTime="25-3-09 8:30:0" />
    <item id="T2" resourceId="R2" name="Raio-X"
    startTime="25-3-09 9:0:0" endTime="25-3-09 9:15:0" />
    <item id="T3" resourceId="R3" name="Analises"
    startTime="25-3-09 12:0:0" endTime="25-3-09 12:45:0" />
    <item id="T4" resourceId="R4" name="Consulta"
    startTime="26-3-09 8:0:0" endTime="26-3-09 9:0:0" />
    </items>
    And I solve it with this (don't know if is the best):
    private function onResultHttpServiceTask(e:ResultEvent):void
    var a:Array = xmlListToObjectArray(e.result.item);
    tasks = new ArrayCollection(a);
    protected function
    xmlListToObjectArray(xmlList:XMLList):Array
    var a:Array = new Array();
    for each(var xml:XML in xmlList)
    var attributes:XMLList = xml.attributes();
    var o:Object = new Object();
    for each (var attribute:XML in attributes)
    var nodeName:String = attribute.name().toString();
    var value:*;
    value = attribute.toString();
    o[nodeName] = value;
    a.push(new ObjectProxy(o));
    return a;
    But when the children "enter in action" I don't know how to
    bring them to the array...
    This code you send it's preaty much the thing I need, but the
    thing is that I don't know how to call the children with data as
    e:ResultEvent...
    If you can help a bit more, I would really appreciate...
    Thank You

  • What is the proper way to set character encoding in an HTTPService request?

    I'm trying to get an HTTPService object's request to have
    proper character encoding. If I do nothing, I get "null" inside a
    Java servlet when I call getCharacterEncoding() on the request
    object. If I do this to my Flex HTTPService:
    httpService.contentType = "application/x-www-form-urlencoded;
    charset=UTF-8";
    then I get a valid character encoding (UTF-8) in the Java
    servlet as I should. But the problem is that my HTTPService's POST
    parameters are no longer coming along with the request. If I drop
    the charset value and set this instead in Flex:
    httpService.contentType =
    "application/x-www-form-urlencoded";
    then I get my POST params in my servlet just fine, but of
    course, no charset info.
    (For completeness, I am also setting: httpService.method =
    "POST"; and httpService.resultFormat = "e4x"; as well as the URL.)
    How do I send charset info without interfering with the
    transmission of the POST params? This is a serious flaw for anyone
    doing UTF-8 content, because most servers are going to assume
    ISO-8859-1 if you don't send anything specific. It's interesting
    that Flex is actually encoding in UTF-8. I know, because I am
    currently working around the problem by intercepting the HTTP
    request in my servlet and forcing the character encoding to UTF-8
    before binding the params. That's a lousy workaround, though.
    Hint to Flex 3 developers: It would be much more preferable
    to have a setCharacterEncoding method (or characterEncoding prop)
    on the Flex HTTPService.

    Hello,
    I realize this is an old thread, but the problem still seems
    to exist in Flex 3 and I run into it
    Unfortunately I don't understand the workaround.
    Could someone point out in a bit more detail how this should
    be done?
    Many thanks indeed,
    Peter
    _servlet = new HTTPService();
    _servlet.url= ...;
    _servlet.resultFormat=_resultFormat;
    _servlet.addEventListener(ResultEvent.RESULT,onServiceActionResult);
    _servlet.addEventListener(FaultEvent.FAULT,onServiceActionFault);
    _servlet.requestTimeout=_timeout;
    _servlet.contentType=_requestMimeType;
    _servlet.method=_method;
    XML.prettyPrinting=false;
    if(sdk13922Workaround) {
    _servlet.request=params;
    this._token=_servlet.send(null);
    } else {
    _servlet.request=request;
    this._token=_servlet.send(_params);
    quote:
    Text

  • Translate HTTPService request to the plain URI

    I'm using following AS code in Flex to get a person's profile:
    var httpService:HTTPService = new HTTPService();
    httpService.url="http://xyz.com/php/profile.php";
    httpService.useProxy=false;
    httpService.method="POST";
    httpService.resultFormat="e4x";
    httpService.addEventListener("result", httpResult);
    httpService.addEventListener("fault", httpFault);
    var code:Object = new Object();
    code.action="getProfile";              
    code.first_name="John";
    code.last_name="Smith";
    var ret:AsyncToken = httpService.send(code);
    How do I translate the above code into plain HTTP request as you type in a browser's address bar?
    I tried the following:
    http://xyz.com/php/profile.php?action=getProfile&first_name=John&last_name=Smith
    get nothing back. I know I'm using "GET" method in the browser's address bar.

    I'm using following AS code in Flex to get a person's profile:
    var httpService:HTTPService = new HTTPService();
    httpService.url="http://xyz.com/php/profile.php";
    httpService.useProxy=false;
    httpService.method="POST";
    httpService.resultFormat="e4x";
    httpService.addEventListener("result", httpResult);
    httpService.addEventListener("fault", httpFault);
    var code:Object = new Object();
    code.action="getProfile";              
    code.first_name="John";
    code.last_name="Smith";
    var ret:AsyncToken = httpService.send(code);
    How do I translate the above code into plain HTTP request as you type in a browser's address bar?
    I tried the following:
    http://xyz.com/php/profile.php?action=getProfile&first_name=John&last_name=Smith
    get nothing back. I know I'm using "GET" method in the browser's address bar.

  • HTTPService and requestTimeout connection issue.

    I could really use some help with using the requestTimeout with HTTPService. I have successfully coded the timeout to 10 seconds and tested it with a long running http request. After 10 seconds the fault listener does execute properly. The trouble I have been observing is extreme delays when other HTTPServices starting and completing. There were major delays with them finishing their http request. At this point I fired up the fiddler web debugger. It appears that the http request does not disconnect after the timeout logic is called in actionscript. I have also tried the HTTPServices disconnect method in the fault listener. Does anyone have any suggestions? Thanks in advance. Here is my test  code: private var httpService:HTTPService = null; private function  TestTimeOut():void
    httpService = new HTTPService();
    httpService.url = "http://someurl";
    httpService.method = "post";
    httpService.resultFormat = "e4x";
    httpService.requestTimeout = 10;
    httpService.addEventListener(FaultEvent.FAULT, onFaultHttpService);
    httpService.addEventListener(ResultEvent.RESULT,  onResultHttpService);
    httpService.send();
    } protected function onResultHttpService(e:ResultEvent):void
    Alert.show("Success.");
    } protected function onFaultHttpService(e:FaultEvent):void
    httpService.disconnect();
    Alert.show("Failed.");

    I could really use some help with using the requestTimeout with HTTPService. I have successfully coded the timeout to 10 seconds and tested it with a long running http request. After 10 seconds the fault listener does execute properly. The trouble I have been observing is extreme delays when other HTTPServices starting and completing. There were major delays with them finishing their http request. At this point I fired up the fiddler web debugger. It appears that the http request does not disconnect after the timeout logic is called in actionscript. I have also tried the HTTPServices disconnect method in the fault listener. Does anyone have any suggestions? Thanks in advance. Here is my test  code: private var httpService:HTTPService = null; private function  TestTimeOut():void
    httpService = new HTTPService();
    httpService.url = "http://someurl";
    httpService.method = "post";
    httpService.resultFormat = "e4x";
    httpService.requestTimeout = 10;
    httpService.addEventListener(FaultEvent.FAULT, onFaultHttpService);
    httpService.addEventListener(ResultEvent.RESULT,  onResultHttpService);
    httpService.send();
    } protected function onResultHttpService(e:ResultEvent):void
    Alert.show("Success.");
    } protected function onFaultHttpService(e:FaultEvent):void
    httpService.disconnect();
    Alert.show("Failed.");

  • DataGrid does not display XML data

    Hello, and thanks for reading this...
    I am having a problem displaying XMLList data in a DataGrid.
    The data is coming from a Tree control, which is receiving it
    from a database using HTTPService.
    The data is a list of "Job Orders" from a MySQL database,
    being formatted as XML by a PHP page.
    If it would be helpful to see the actual XML, a sample is
    here:
    http://www.anaheimwib.com/_login/get_all_orders_test2.php
    All is going well until I get to the DataGrid, which doesn't
    display the data, although I know it is there as I can see it in
    debug mode. I've checked the dataField property of the appropriate
    DataGrid column, and it appears correct.
    Following is a summary of the relevant code.
    ...An HTTPService named "get_all_job_orders" retrieves
    records from a MySQL database via PHP...
    ...Results are formatted as E4X:
    HTTPService resultFormat="e4x"
    ...An XMLListCollection's source property is set to the
    returned E4X XML results:
    ...The "order" node is what is being used as the top-level of
    the XML data.
    <mx:XMLListCollection id="jobOrdersReviewXMLList"
    source="{get_all_job_orders.lastResult.order}"/>
    ...The "jobOrdersReviewXMLList" collection is assigned to be
    the dataProvider property of a Tree list, using the @name syntax to
    display the nodes correctly, and a change event function is defined
    to add the records to a DataGrid on a separate Component for
    viewing the XML records:
    <mx:Tree dataProvider="{jobOrdersReviewXMLList}"
    labelField="@name"
    change="jobPosForm.addTreePositionsToDG(event)"/>
    ...Here is the relevant "jobPosForm" code (the Job Positions
    Form, a separate Component based on a Form) :
    ...A variable is declared:
    [Bindable]
    public var positionsArray:XMLList;
    ...The variable is initialized on CreationComplete event of
    the Form:
    positionsArray = new XMLList;
    ...The Tree's change event function is defined within the
    "jobPosForm" Component.
    ...Clicking on a Tree node fires the Change event.
    ...This passes an event object to the function.
    ...This event object contains the XML from the selected Tree
    node.
    ...The Tree node's XML data is passed into the positionsArray
    XMLList.
    ...This array is the dataProvider for the DataGrid, as you
    will see in the following block.
    public function addTreePositionsToDG(event:Event):void{
    this.positionsArray = selectedNode.positions.position;
    ...A datagrid has its dataProvider is bound to
    positionsArray.
    ...(I will only show one column defined here for brevity.)
    ...This column has its dataField property set to "POS_TITLE",
    a field in the returned XML record:
    <mx:DataGrid width="100%" variableRowHeight="true"
    height="75%" id="dgPositions"
    dataProvider="{positionsArray}" editable="false">
    <mx:columns>
    <mx:DataGridColumn width="25" headerText="Position Title"
    dataField="POS_TITLE"/>
    </mx:columns>
    </mx:DataGrid>
    In debug mode, I can examine the datagrid's dataProvider
    property, and see that the correct XML data from the Tree control
    is present. However, The datagrid does not display the data in any
    of its 6 columns.
    Does anyone have any advice?
    Thanks for your time.

    Hello again,
    I came up with a method of populating the DataGrid from the
    selected Item of a Tree Control which displays complex XML data and
    XML attributes. After the user clicks on a Tree branch, I call this
    function:
    public function addTreePositionsToDG(event:Event):void{
    //Retrieve all "position" nodes from tree.
    //Loop thru each Position.
    //Add Position data to the positionsArray Array Collection.
    //The DataGrid dataprovider is bound to this array, and will
    be updated.
    positionsArray = new ArrayCollection();
    var selectedNode:Object=event.target.selectedItem;//Contains
    entire branch.
    for each (var position:XML in
    selectedNode.positions.position){
    var posArray:Array = new Array();
    posArray.PK_POSITIONID = position.@PK_POSITIONID;
    posArray.FK_ORDERID = position.@FK_ORDERID;
    posArray.POS_TITLE = position.@POS_TITLE;
    posArray.NUM_YOUTH = position.@NUM_YOUTH;
    posArray.AGE_1617 = position.@AGE_1617;
    posArray.AGE_1821 = position.@AGE_1821;
    posArray.HOURS_WK = position.@HOURS_WK;
    posArray.WAGE_RANGE_FROM = position.@WAGE_RANGE_FROM;
    posArray.WAGE_RANGE_TO = position.@WAGE_RANGE_TO;
    posArray.JOB_DESCR = position.@JOB_DESCR;
    posArray.DES_SKILLS = position.@DES_SKILLS;
    positionsArray.addItem(posArray);
    So, I just had to manually go through the selected Tree node,
    copy each XML attribute into a simple Array, then ADD this Array to
    an ArrayCollection being used as the DataProvider for the DataGrid.
    It's not elegant, but it works and I don't have to use a Label
    Function, which was getting way too complicated. I still think that
    Flex should have an easier way of doing this. There probably is an
    easier way, but the Flex documentation doesn't provide an easy path
    to it.
    I want to thank you, Tracy, for the all the help. I checked
    out the examples you have at www.cflex.net and they are very
    helpful. I bookmarked the site and will be using it as a resource
    from now on.

  • Flex Grid Issues

    Hi,
    I am using Flex Grid in my project where i am successfully able to populate xml data dynamically. what i am doing here, I am dynamically generating the xml using httpservice. This HttpService is returning an XmlList that i am using to bind the grid dynamically.
    Here i am not fixing the column header text and column width as  in future the number of cloumns can be increased so i can't fix the column header text and column width.
    Here the issue is: how to remove " _x0020_"  from the header text and how to fix column width dynamically using Action Script.
    For better idea please refer the screen shot as attached along with post.
    Please have a look on the code as pasted below:
    <?xml version="1.0" encoding="utf-8"?><mx:Canvas 
    xmlns:mx="http://www.adobe.com/2006/mxml" width="862" height="580"><mx:TitleWindow 
    x="182" y="113" width="670" height="395" layout="vertical" title="
    Top Presenters" fontSize="12"horizontalAlign="
    center" verticalAlign="top" showCloseButton="true" close="CloseGridWindow()" verticalScrollPolicy="
    off" borderColor="#000000"horizontalScrollPolicy="
    off" borderThicknessLeft="3"borderThicknessRight="
    3" borderThicknessBottom="3" creationComplete="GetTopPresentersXMLData()" backgroundColor="
    #FFFFFF" cornerRadius="
    0" color="#FFFFFF" >
    <mx:Script><![CDATA[
    import mx.controls.dataGridClasses.DataGridColumn; 
    import mx.collections.XMLListCollection; 
    import mx.managers.PopUpManager; 
    import mx.rpc.events.FaultEvent; 
    import mx.rpc.events.ResultEvent; 
    import mx.rpc.http.HTTPService; 
    import mx.events.FlexEvent; 
    import mx.controls.Alert; 
    //funtion to get Top Presenters xml data 
    private function GetTopPresentersXMLData():void{
    var httpService:HTTPService = new HTTPService();httpService.url =
    "http://ri/CItSL/Ters.aspx?mode=all&month=march&year=2009";httpService.resultFormat =
    "e4x";httpService.addEventListener(ResultEvent.RESULT, onResultHttpService);
    httpService.send();
    Bindable] 
    private var _xmlData:XMLList; 
    //funtion to receive Http Service Response as XML Document  
    private function onResultHttpService(e:ResultEvent):void{
    var xmlData:XMLList = e.result.Table;myGrid.dataProvider = xmlData;
    for each (var node:XML in xmlData[0].children()){
    addDataGridColumn(node.name());
    //function to add column dynamically  
    private function addDataGridColumn(dataField:String):void{
    //var spacePattern:RegExp=/_x0020_/g; 
    //var andPattern:RegExp=/_x0026_/g; 
    //dataField=dataField.replace(spacePattern," "); 
    //dataField=dataField.replace(andPattern,"&"); 
    var dgc:DataGridColumn=new DataGridColumn(dataField); 
    var cols:Array=myGrid.columns;cols.push(dgc);
    myGrid.columns=cols;
    myGrid.validateNow();
    //funtion to remove grid window 
    private function CloseGridWindow():void{
    PopUpManager.removePopUp(
    this);}
    ]]>
    </mx:Script>  
    <mx:DataGrid id="myGrid" alternatingItemColors="[#A2F4EF, #EFDE7D]" x="0" y="0" sortableColumns="false" width="658" height="352" fontSize="10" verticalAlign="middle" editable="false" enabled="true" horizontalGridLineColor="#befcc4" color="#000000">  
    </mx:DataGrid>
    </mx:TitleWindow>
    Please let me know, If anyone knows the solution.

    Hi,
    You can follow the below mentioned code and see if this works for you.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
        creationComplete="onComplete();">
        <mx:Script>
            <![CDATA[
                // imports:
                import mx.events.FlexEvent;
                import mx.core.UIComponent;
                import mx.controls.dataGridClasses.DataGridColumn;
                import mx.controls.Text;
                import mx.utils.ObjectUtil;
                import mx.controls.Label;
                import mx.collections.ArrayCollection;
                // data provider:
                [Bindable] private var dp:ArrayCollection = new ArrayCollection();
                private function onComplete():void {
                    // populate data provider here
                    // to avoid calcMaxLengths execution when the app is created:
                    dp = new ArrayCollection(
                            { col1: "Short", col2: "Other column 1" },
                            { col1: "Some long string", col2: "Other column 2" },
                            { col1: "Short", col2: "Other column 3" },
                            { col1: "Short", col2: "Other column 4" },
                            { col1: "The longest value in this column", col2: "Other column 5" },
                            { col1: "Short", col2: "Other column 6" },
                            { col1: "Short", col2: "Other column 7" }
                // this is going to be executed whenever the data provider changes:
                [Bindable("dataChange")]
                private function calcMaxLengths(input:ArrayCollection):ArrayCollection {
                    // if there are items in the DP:
                    if ( input.length > 0 ) {
                        // and no SPECIAL child exists:
                        if ( getChildByName("$someTempUICToRemoveAfterFinished") == null ) {
                            // create new SPECIAL child
                            // this is required to call measureText
                            // if you use custom data grid item renderer
                            // then create instance of it instead of UIComponent:
                            var uic:UIComponent = new UIComponent();
                            // do not show and do not mess with the sizes:
                            uic.includeInLayout = false;
                            uic.visible = false;
                            // name it to leverage get getChildByName method:
                            uic.name = "$someTempUICToRemoveAfterFinished";
                            // add event listener:
                            uic.addEventListener(FlexEvent.CREATION_COMPLETE, onTempUICCreated);
                            // add to parent:
                            addChild(uic);
                    // return an input:
                    return input;
                // called when SPECIAL child is created:
                private function onTempUICCreated(event:FlexEvent):void {
                    // keep the ref to the SPECIAL child:
                    var renderer:UIComponent = UIComponent(event.target);
                    // output - this will contain max size for each column:
                    var maxLengths:Object = {};
                    // temp variables:
                    var key:String = "";
                    var i:int=0;
                    // for each item in the DP:
                    for ( i=0; i<dp.length; i++ ) {
                        var o:Object = dp.getItemAt(i);
                        // for each key in the DP row:
                        for ( key in o ) {
                            // if the output doesn't have current key yet create it and set to 0:
                            if ( !maxLengths.hasOwnProperty(key) ) {
                                maxLengths[key] = 0;
                            // check if it's simple object (may cause unexpected issues for Boolean):
                            if ( ObjectUtil.isSimple(o[key]) ) {
                                // measure the text:
                                var cellMetrics:TextLineMetrics = renderer.measureText(o[key]+"");
                                // and if the width is greater than longest found up to now:
                                if ( cellMetrics.width > maxLengths[key] ) {
                                    // set it as the longest one:
                                    maxLengths[key] = cellMetrics.width;
                    // apply column sizes:
                    for ( key in maxLengths ) {
                        for ( i=0; i<dg.columnCount; i++ ) {
                            // if the column actually exists:
                            if ( DataGridColumn(dg.columns[i]).dataField == key ) {
                                // set size + some constant margin
                                DataGridColumn(dg.columns[i]).width = Number(maxLengths[key]) + 12;
                    // cleanup:
                    removeChild(getChildByName("$someTempUICToRemoveAfterFinished"));
            ]]>
        </mx:Script>
        <mx:DataGrid id="dg" horizontalScrollPolicy="on" dataProvider="{calcMaxLengths(dp)}" width="400">
            <mx:columns>
                <mx:DataGridColumn dataField="col1" width="40" />
                <mx:DataGridColumn dataField="col2" width="100" />
            </mx:columns>
        </mx:DataGrid>
    </mx:WindowedApplication>
    Regards

  • DisplayObject must be a child of the caller.

    I am trying to remove the existing childs  (combobox and pods are the content in the page) using
    viewStack.selectedChild.removeAllChildren();
    in a tab click from the Viewstacks canvas.
    then I am trying to add new child.
    it gives this error.
    The supplied DisplayObject must be a child of the caller.
    at flash.display::DisplayObjectContainer/getChildIndex()
    at mx.core::Container/setChildIndex()[C:\autobuild\3.2.0\frameworks\projects\framework\src\m x\core\Container.as:2449]
    Please help me to fix this

    private function onApplicationComplete():void{
    var arrView:Array =new Array();arrView=viewStack.getChildren();
    viewLength=arrView.length;
    // Load pods.xml, which contains the pod layout. 
    var httpService:HTTPService = new HTTPService();httpService.url =
    "data/pods.xml";httpService.resultFormat =
    "e4x";httpService.addEventListener(FaultEvent.FAULT, onFaultHttpService);
    httpService.addEventListener(ResultEvent.RESULT, onResultHttpService);
    httpService.send();
    private function onFaultHttpService(e:FaultEvent):void{
    Alert.show(
    "Unable to load data/pods.xml.");}
    public var viewXMLList:XMLList =new XMLList(); 
    private function onResultHttpService(e:ResultEvent):void{
    viewXMLList = e.result.view;
    var podcontentbase:PodContentBase=new PodContentBase; 
    var containerWindowManagerHash:Object = new Object();  
    var len:Number = viewXMLList.length(); 
    if (podLayoutManagers.length!=0)podLayoutManagers.splice(0,podLayoutManagers.length);
    for (var i:Number = 0; i < len; i++) // Loop through the view nodes.{
    // Create a canvas for each view node. 
    var canvas:Canvas = new Canvas(); 
    // PodLayoutManager handles resize and should prevent the need for 
    // scroll bars so turn them off so they aren't visible during resizes.canvas.horizontalScrollPolicy =
    "off";canvas.verticalScrollPolicy =
    "off";canvas.label = viewXMLList[i].@label;
    canvas.percentWidth = 100;
    canvas.percentHeight = 100;
    viewStack.addChild(canvas);
    traceDL(viewStack);
    // Create a manager for each view. 
    var manager:PodLayoutManager = new PodLayoutManager();manager.container = canvas;
    manager.id = viewXMLList[i].@id;
    manager.addEventListener(LayoutChangeEvent.UPDATE, StateManager.setPodLayout);
    // Store the pod xml data. Used when view is first made visible.podDataDictionary[manager] = viewXMLList[i].pod;
    //podcontentbase.podDataDictionarycopy[manager] = viewXMLList[i].pod; 
    podLayoutManagers.push(manager);
    onchange();
    private function onchange():void{
    tabBar.dataProvider=viewStack;
    var index:Number = StateManager.getViewIndex(); 
    // Make sure the index is not out of range. 
    // This can happen if a tab view was saved but then tabs were subsequently removed from the XML.index = Math.min(tabBar.numChildren - 1, index);
    onItemClickTabBar(
    new ItemClickEvent(ItemClickEvent.ITEM_CLICK, false, false, null, index));tabBar.selectedIndex = index;
    private var indextab:Number; 
    private function onItemClickTabBar(e:ItemClickEvent):void{
    indextab = e.index;
    StateManager.setViewIndex(indextab);
    // Save the view index.viewStack.selectedIndex = indextab;
    if( this.contains( viewStack.selectedChild) )viewStack.selectedChild.removeAllChildren();
    traceDL(
    this);

  • Nested XML into comboBox

    Well as stupid as this sounds I can populate a datagrid from
    a dynamic xml source(ASP) using HTTPservice but a basic lack of
    understanding is preventing me from using this data in a comboBox
    Below is my application source that works for populating the
    datagrid in it, but when the data is used in the comboBox as it's
    dataprovider the value is "[object][object]" Ive tried a bunch of
    stuff but I think im conceptualy misunderstanding something about
    retreiving nested values...
    --MY BROKEN EXAMPLE---
    --XML-output-by-asp-document--------
    <product>
    <category>Tile</category>
    <name>Angelic Peach</name>
    </product>
    <product>
    <category>Tile</category>
    <name>Cosmo</name>
    </product>
    <product>
    <category>Tile</category>
    <name>Durva</name>
    </product>
    <product>
    <category>Tile</category>
    <name>Isosilis</name>
    </product>
    <product>
    <category>Tile</category>
    <name>Magaloth</name>
    </product>
    <product>
    <category>Tile</category>
    <name>Trunklin</name>
    </product>
    <product>
    <category>Tile</category>
    <name>Googolfletch</name>
    </product>
    <product>
    <category>Tile</category>
    <name>Moskurbelf</name>
    </product>
    <product>
    <category>Tile</category>
    <name>DoChoaKoa</name>
    </product>
    ---products-component-for-use-in-main-application---
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="400" height="300"
    creationComplete="this.productStream.send();">
    <mx:Script>
    <![CDATA[
    import mx.utils.ArrayUtil;
    import mx.utils.XMLUtil
    //var urlPath="
    http://localhost/rogerwilko/AndeanStone/xml.asp";
    function xmlRequest():void {
    // Cancel all previous pending calls.
    productStream.cancel();
    var params:Object = new Object();
    params.func = 'products';
    productStream.send(params);
    ]]>
    </mx:Script>
    <mx:HTTPService id="productStream"
    url="
    http://localhost/rogerwilko/AndeanStone/xml.asp"/>
    <mx:Label text="Select A Product Category" top="0"
    left="0"/>
    <mx:ComboBox id="prodCatList"
    dataProvider="{mx.utils.ArrayUtil.toArray(this.productStream.lastResult.product)}"
    width="200" left="0" top="20" cornerRadius="3" fillAlphas="[0.5,
    0.5]" themeColor="#00ff00" alpha="0.49">
    </mx:ComboBox>
    <mx:DataGrid id="prodList"
    dataProvider="{mx.utils.ArrayUtil.toArray(this.productStream.lastResult.product)}"
    columnWidth="200" width="200" left="0" top="55">
    <mx:columns>
    <mx:DataGridColumn headerText="{prodCatList.value}"
    dataField="name"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:Canvas>
    Thanks in advance for any help you can provide me
    leo

    You will need to specify either a labelField or
    labelFunction. You can use a labelField if the value you want to
    show in the combo box is a first level property of the item.
    If the data you want to display is deeper in the item object,
    and you need to "dot down" to get it use a labelFunction.
    HTTPService resultFormat defaults to Object. I have never
    been comfortable about the way Flex converts xml into objects, so I
    always use e4x. This choice affects the structure of your item
    objects, and therefore the way you need to access the item objects
    properties.
    Try labelField, anif that doesn't work use a labelFunction.
    Note, you can debug the labelFunction quite handily.
    Tracy

  • All the xml and arrays are getting NULL Problem

    Hello guys
    I am working on a project which uses xml loading, e4x and array manipulation extensively, and it was going good but now I got stuck on a strange problem.  Whole code was fine and application was working and responding in a desired way, but then mystourisly it stopped working and started to retun NULL values to almost all the actionscript (internal) Arrays and XML varibales.
    Now Whenever i load xml file and assign the loaded values to internal xml variables, internal values get only NULL instead of data.
    Same is the situation with Arrays, I created some components in mxml, and when i passed them to arrays by reference, code gets compiled successfully, but again Array has only null values [that code was working fine too]
    I am wondering if Adobe Flex did a silenced update or something similar and it is the result of that things !
    I am using Adobe Flex 3.2 with SDK 3.3 on windows Vista Ultimate.
    Please check this attached project, Import it and see if you face the same problem
    Thanks
    Link to Problem Project
    http://isolatedperson.googlepages.com/problemXperiment.zip
    Problem Screenshot
    http://isolatedperson.googlepages.com/xmlissue.JPG

    Use HTTPService to load the data. You'll have fewer problems.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application creationComplete="dataSvc.send();"
      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
         <mx:Script>
              <![CDATA[
                import mx.collections.XMLListCollection;
                import mx.rpc.events.ResultEvent;
                [Bindable] private var xlc:XMLListCollection;
                   private function loadXML(evt:ResultEvent):void{
                    xlc =  new XMLListCollection(evt.result.individual.@id as XMLList);
              ]]>
         </mx:Script>
         <mx:HTTPService resultFormat="e4x" result="loadXML(event)" url="alirazaTree.xml" id="dataSvc"/>
         <mx:ComboBox id="cbx" dataProvider="{xlc}"/>
    </mx:Application>

  • Reading complex XML file in flex

    I have searched the web but found very primitive xml
    examples. I want to read a complex xml file which through
    httpservice .
    The xml file is ultimately going to become dataProvider of a
    tree. But I have no idea how to traverse this xml file. mentioned
    under are the xml file and HTTPService tag.
    I want to traverse it in the resultHandler function.
    Thank you very much

    Yes, as Greg says, use e4x.
    To do this you must set the HTTPService resultFormat="e4x";
    In you handler, do:
    var xmlResult= XML(event.result);
    trace(xmlResult.toXMLString());
    and away you go.
    Tracy

Maybe you are looking for

  • BADI for defaulting the ITEM data

    Hi, I have to default a field in Item level for shopping cart  but the default value should be editable to the user. I tried using the BADI BBP_DOC_CHANGE_BADI but does not helps because it is gets triggered when even any item is changed. The require

  • Creating a System in System Landscape of EP7.0 connecting to ESS6.0

    Could someone explain in detail and hopefully with examples, of the process of creating the System with the alias 'SAP_WebDynpro_XSS' in the System Landscape when implementing ESS. I am getting an error message of wrong password, and I think it has t

  • Total Hours Computer Has Been On

    I would like to know the total hours my computer has been on. I know there are commands to give uptime since power on but I remember a tool or utility that could report the cumulative hours the computer has been on (this was back in MacPlus days). An

  • Library Module - Quick Develop Panel

    Hi, I was really hoping that the Quick Develop panel in the Library Module which I sometimes use if there are minor touchups needed to a photo would have been redesigned to more closely resemble and work like the Basic panel in the Develop Module.  C

  • Availability monitoring using ccmsping - refresh rate

    So I've configured my solman 3.2 to monitor the availability of other systems via the use of ccmsping.  I can see the other systems well enough, but the problem is the long time it takes for my solman system to become aware that a monitored system is