Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Newby Questions with HTTPService / Flex 3

Avatar

Level 1
Hi folks. I am a pretty experienced database programmer, I
work with a software called Magic eDev, but I'm a newby in Flex.



I am trying to use Flex 3 to create a web / client interface
for an application written in Magic eDev. I am still trying to get
my head around Flex, (Magic is a completely different programming
paradigm) and I've made a very simple Flex App to read an XML file
generated by another application written in a third party software
(Magic eDev 9.4) via HTTPService. I think I have the HTTPService
request part figured out, This little Application does not cause
any errors. However, I am not seeing my data in the display. If I
manually try the URL query to the Magic App, I do get the XML file
with the data in it, but Flex doesn't seem to see anything.



I just want to get two fields via the HTTPService data and
display them, but I'm not getting any result. I can't even tell if
Flex is actually querying Magic or not. Can anyone explain what I'm
doing wrong?



Also, is there some way to monitor what the Flex app is doing
when you run it, as you can in some other systems?



Here is my code:

<?xml version="1.0" encoding="utf-8"?>



<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"

layout="vertical"

verticalAlign="middle"

backgroundColor="white">



<mx:Script>

<![CDATA[

import mx.rpc.events.FaultEvent;

import mx.rpc.events.ResultEvent;

private function serv_result(evt:ResultEvent):void {

var resultObj:Object = evt.result;

userName.text = resultObj.catalog.username;

emailAddress.text = resultObj.catalog.emailaddress;

}

private function serv_fault(evt:FaultEvent):void {

error.text += evt.fault.faultString;

error.visible = true;

form.visible = false;

}

]]>

</mx:Script>



<mx:String id="XML_URL">album.xml</mx:String>

<mx:HTTPService id="loginService"

url="
http://localhost/magic94scripts/mgrqcgi94.exe"

method="POST"

result="{ResultEvent(event)}"
fault="{FaultEvent(event)}">



<mx:request>

<appname>FlexDispatch</appname>

<prgname>Test</prgname>

<arguments>username,emailaddres</arguments>

</mx:request>

</mx:HTTPService>



<mx:ApplicationControlBar dock="true">

<mx:Label text="{XML_URL}" />

</mx:ApplicationControlBar>

<mx:Label id="error"

color="red"

fontSize="36"

fontWeight="bold"

visible="false"

includeInLayout="{error.visible}"/>

<mx:Form id="form"

includeInLayout="{form.visible}">

<mx:FormItem label="resultObj.catalog.username:">

<mx:Label id="userName" />

</mx:FormItem>

<mx:FormItem label="resultObj.catalog.emailaddress:">

<mx:Label id="emailAddress" />

</mx:FormItem>

</mx:Form>

</mx:Application>



This is what the XML file looks like:



<?xml version="1.0" ?>

- <catalog>

<username>DaveID</username>

<emailaddress>DaveName</emailaddress>

</catalog>
1 Reply

Avatar

Former Community Member
Man, I really thought I could nail this one, but alas I could
not. The attached code simplifies yours, and in fact mine might
have problems that would prevent data from displaying but notice
these points:

- you don't seem to call the send() method to actually send
the request

- I use trace statements to at least know something it
happening



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"

creationComplete="trace('in
creationComplete');loginService.send()">

<mx:Script>

<![CDATA[

import mx.rpc.events.FaultEvent;

import mx.rpc.events.ResultEvent;

private function serv_result(evt:ResultEvent):void {

trace("got here");

var resultObj:Array = loginService.lastResult.catalogs;

userName.text = resultObj[0][0];

emailAddress.text = resultObj[0][1];

}

private function serv_fault(evt:FaultEvent):void {

trace("oops, got here");

error.text += evt.fault.faultString;

}

]]>

</mx:Script>

<mx:HTTPService id="loginService" resultFormat="array"
url="file.xml"

result="ResultEvent(event)" fault="FaultEvent(event)">

</mx:HTTPService>

<mx:Label id="userName" text="Greg"/>

<mx:Label id="emailAddress" text="Greg@greg.com"/>

<mx:Label id="error" text="error text"/>

</mx:Application>