Adobe Dreamweaver Forums



Last 10 THreads :         Re: Mouse capture won't activate (Last Post : robertnagle - Replies : 0 - Views : 1 )           »          help! my FB3 has gone insane! (Last Post : peteandrus - Replies : 0 - Views : 1 )           »          help! my FB3 has gone insane! (Last Post : peteandrus - Replies : 0 - Views : 1 )           »          How come the html is being displayed, and not the link (Last Post : Skaterstu - Replies : 0 - Views : 1 )           »          Another way to accomplish this (Last Post : Andy-K - Replies : 2 - Views : 3 )           »          HELP! Cannot upload files in DW CS4 (Last Post : dan@hoppernet.org - Replies : 6 - Views : 7 )           »          Adobe Flash 10 kills Wimpy (Last Post : m77ty8uu - Replies : 32 - Views : 208 )           »          How do I unlock all files in site at once (Last Post : Alan - Replies : 1 - Views : 2 )           »          Load library clip into target on stage (Last Post : NedWebs - Replies : 5 - Views : 8 )           »          This HAS to work... I'm going wacky (Last Post : David Stiller - Replies : 5 - Views : 6 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags: , ,



Reply
  #1 (permalink)  
Old 09-05-2008, 03:43 AM
SiHoop
 
Posts: n/a
Diggs:
Default Converting HTTPService to AS3

One of the things I don't like about Flex is having to flip between xmxl and
..as files as I am working through the logic of my code. As a result, I want to
convert all of my HTTPService tags to AS3. I don't see any point in writing the
HTTPService in mxml as there is no visual element to it. So my question is
this: Can I simply use a loadVars object to manage my calls and returns to and
from php (does it even exist in AS3?), or should I be using the HTTPService in
AS3. If I should be using the HTTPService in AS3, how would I write the
following?

Many thanks for looking.

<mx:HTTPService id="login_user" result="checkLogin(event)" method="GET"
useProxy="false" url="http://localhost/admin_php/login.php">
<mx:request xmlns="">
<username>
{username}
</username>
<password>
{password}
</password>
</mx:request>
</mx:HTTPService>



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-05-2008, 05:40 AM
Ben Yee
 
Posts: n/a
Diggs:
Default Re: Converting HTTPService to AS3

If you're having issues with declaring your Services inside your MXML
you might want to look at using some kind of framework such as
Cairngorm. Cairngorm provides a ServiceLocator which allows you to
declare all your services in one place. Each service has an id and
can be referenced by calling this.service =
ServiceLocator.getInstance().getHTTPService( "yourserviceid" );

But if you do *really* want this in Actionscript and still have it
residing in the MXML then you would need to declare it somethings like
this

var service:HTTPService = new HTTPService();
service.url = "";
etc..

Cheers
Ben


On Sep 5, 12:27*pm, "SiHoop" <webforumsu...@macromedia.com> wrote:
> One of the things I don't like about Flex is having to flip between xmxl and
> .as files as I am working through the logic of my code. As a result, I want to
> convert all of my HTTPService tags to AS3. I don't see any point in writing the
> HTTPService in mxml as there is no visual element to it. So my question is
> this: Can I simply use a loadVars object to manage my calls and returns to and
> from php (does it even exist in AS3?), or should I be using the HTTPService in
> AS3. If I should be using the HTTPService in AS3, *how would I write the
> following?
>
> *Many thanks for looking.
>
> *<mx:HTTPService id="login_user" result="checkLogin(event)" *method="GET"
> useProxy="false" url="http://localhost/admin_php/login.php">
> * * * * <mx:request xmlns="">
> * * * * * * * * <username>
> * * * * * * * * * * * * {username}
> * * * * * * * * </username>
> * * * * * * * * <password>
> * * * * * * * * * * * * {password}
> * * * * * * * * </password>
> * * * * </mx:request>
> *</mx:HTTPService>


Reply With Quote
  #3 (permalink)  
Old 09-05-2008, 05:40 AM
Amy Blankenship
 
Posts: n/a
Diggs:
Default Re: Converting HTTPService to AS3


"SiHoop" <webforumsuser@macromedia.com> wrote in message
news:g9q5e8$nhr$1@forums.macromedia.com...
> One of the things I don't like about Flex is having to flip between xmxl
> and
> .as files as I am working through the logic of my code. As a result, I
> want to
> convert all of my HTTPService tags to AS3. I don't see any point in
> writing the
> HTTPService in mxml as there is no visual element to it. So my question is
> this: Can I simply use a loadVars object to manage my calls and returns to
> and
> from php (does it even exist in AS3?), or should I be using the
> HTTPService in
> AS3. If I should be using the HTTPService in AS3, how would I write the
> following?
>
> Many thanks for looking.
>
> <mx:HTTPService id="login_user" result="checkLogin(event)" method="GET"
> useProxy="false" url="http://localhost/admin_php/login.php">
> <mx:request xmlns="">
> <username>
> {username}
> </username>
> <password>
> {password}
> </password>
> </mx:request>
> </mx:HTTPService>


There's a sort of crap example at the bottom of this page that might point
you in the right direction
http://www.adobe.com/livedocs/flex/3..._access_2.html
Here's another example that's about something else but you may find useful
http://thanksmister.com/?p=43


Reply With Quote


  #4 (permalink)  
Old 09-05-2008, 06:17 AM
greg h_
 
Posts: n/a
Diggs:
Default Re: Converting HTTPService to AS3

Hi SiHoop,

The last section on the doc page at the following link is entitled "Calling
HTTP services in ActionScript"
http://livedocs.adobe.com/flex/3/htm..._access_2.html

I also have an issue switching between mxml to as. And once I get going I
tend to prefer just staying in ActionScript.

One great thing about using microarchitectures like Cairngorm or PureMVC is
that outside of the view, they generally mandate using ActionScript.
(Although, I do have Service classes where I still use MXML on the RPC classes.
6 of 1, half dozen of another. Just so long as it works ;-)

Please post back regarding whether the above answers your question, and if
you find it helpful :-)


Best regards,

g

Reply With Quote
  #5 (permalink)  
Old 09-05-2008, 06:40 AM
greg h_
 
Posts: n/a
Diggs:
Default Re: Converting HTTPService to AS3

P.S.

The Flex 2 docs on "http://livedocs.adobe.com/flex/2/docs/00001932.ht ml" say:
ActionScript 3.0 has replaced the LoadVars class with URLLoader and
URLVariables classes.

The Flex 3 docs on "Using the URLLoader and URLVariables classes" are here:
http://livedocs.adobe.com/flex/3/htm...cations_3.html


The docs there comment:
The new event-handling model is a significant improvement over the
ActionScript 2.0 support for the LoadVars.onData, LoadVars.onHTTPStatus, and
LoadVars.onLoad event handlers because it allows you to handle errors and
events more efficiently.

Again, hth,

g

Reply With Quote
  #6 (permalink)  
Old 09-05-2008, 03:03 PM
SiHoop
 
Posts: n/a
Diggs:
Default Re: Converting HTTPService to AS3

greg h_,

Thanks for the two replies. I took a look at the page your recommended
http://livedocs.adobe.com/flex/3/htm..._access_2.html I am frustrated with
the explanation for two reasons. First, when I use the sample code to simply
fire a php page I get an error message back. It seems that I am unable to even
hit the file which I know is running properly when I test it via a web browser.
Second, I do not know how to aggregate the data that is to be sent. The example
indicates that I am supposed to use the following, but I do not know how to
send through my data as 'parameters:Object', in part because my data are stored
in text variables:

public function useHttpService(parameters:Object):void {

I wish the example provided by adobe had been a direct translation of the
sample code given in the section titled MXML code, including an explanation of
how to include the username and emailaddress included in the <mx:request> tag.
So my question to you is: How do I specify the variables that I am to send?

Thanks also for the explanation of how to load data from external documents in
AS3-- very important! Below is the code I used to try to fire the php page:


<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="useHttpService()" verticalGap="10">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.http.HTTPService;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
private var service:HTTPService

public function useHttpService():void {
service = new HTTPService();
service.destination = "http://localhost/admin_php/login.php";
service.method = "POST";
service.addEventListener("result", httpResult);
service.addEventListener("fault", httpFault);
service.send()//(parameters);
}

public function httpResult(event:ResultEvent):void {
var result:Object = event.result;
trace(event.result.mydata)
}

public function httpFault(event:FaultEvent):void {
var faultstring:String = event.fault.faultString;
Alert.show(faultstring);
}
]]>
</mx:Script>
</mx:Application>

Reply With Quote


  #7 (permalink)  
Old 09-05-2008, 04:44 PM
greg h_
 
Posts: n/a
Diggs:
Default Re: Converting HTTPService to AS3

Hi SiHoop,

In the following documentation page, please see under the heading "Explicit
parameter passing with HTTPService components":
http://livedocs.adobe.com/flex/3/htm..._access_5.html

Basically there are 3 ways to pass params to the server via HTTPService:
1) Bindings (in link above, see heading "Parameter binding with
HTTPService components"). This option mainly applies when instantiating
HTTPService via MXML (i.e. <mx:HTTPService>), not when instantiating via
ActionScript (as you are doing).
2) In send() by position relative to how defined on serverside method
(e.g. myService.send( myText.text, myText2.text )
3) In send() via object w/ properties that match param names defined on
serverside method
, (e.g.
var params:Object = new Object();
params.param1 = myText.text;
params.param2 = myText2.text;
myService.send(params);

For option 3 above, please note that in
http://livedocs.adobe.com/flex/3/htm..._access_2.html, where their
"parameters:Object" was being passed in on the signature of the method
definition of useHttpService(parameters:Object), the object parameters would
have been built in the calling code. Unfortunately, the current version of
that documentation does not show any calling code. (Just before I had replied
last night, Amy had fairly posted that this was "a sort of crap example".) So,
depending on your requirement you can build the object elsewhere and pass it
in, or you can build the object immediately before executing send(params).

btw, Following is a "Flex quick start guide for PHP developers" complete with
sample files. It does not cover executing HTTPService via ActionScript.
However, if you have not yet reviewed it, perhaps it may help you with some
working examples of Flex working with PHP backends.

Please post back regarding whether the above answers your question, and if
you find it helpful :-)


Best regards,

g

Reply With Quote
  #8 (permalink)  
Old 09-05-2008, 05:36 PM
greg h_
 
Posts: n/a
Diggs:
Default Re: Converting HTTPService to AS3

P.S.

In my last post I forgot to add the following link where I had written "btw,
Following is a "Flex quick start guide for PHP developers" ... "
http://www.adobe.com/devnet/flex/art...etstarted.html

Even better may be the Flex 3 "Getting Started" examples that also provide
complete with sample files:
http://learn.adobe.com/wiki/display/Flex/2b.+Code+Files
This link is into "Part II. Exchanging Data", "2b. Code Files"

The related page to "Download preconfigured Flex Builder projects" is here:
http://learn.adobe.com/wiki/display/...nload+Projects

Again, the examples I am providing these links into do not cover executing
HTTPService via ActionScript. They do, however, provide working examples of
Flex working with PHP backends.

Please post back regarding whether the above answers your question, and if
you find it helpful :-)


Best regards,

g

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 02:15 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk