Newbie Q: HTTPService in ActionScript

I am a complete newbie - I looked at the stuff "learn flex in a week" and read a few tutorials, but otherwise I'm from scratch.  I'm trying to create an HTTPService object purely in ActionScript, mainly because I just think it seems cleaner that to have all parts of separate functions, tags object declaration, etc..  Feel free to convince me that stylistically, this is the wrong choice.

I started by doing the opposite, which is in all the examples.  This loads a configuration data object.  One of the elements is another URL which must be loaded, so I did this:

private void configLoadedOK(event:ResultEvent):void {}
config = event.result.thisMoment;
trace (config. LINKS. GET_META_DATA.value);
var metadataHTTP:HTTPService = new HTTPService;
metadataHTTP.url = config. LINKS. GET_META_DATA. Value;
metadataHTTP.fault = function (): void {}
Alert.Show ("Unable to load metadata.", "Error");
}
metadataHTTP.result = {function(metaevent:ResultEvent):void}
metadata = metaevent.result.moment_info;
trace ("metadata loaded" + metadata);
}
metadataHTTP.send ();
}

They do not compile.  The "metadataHTTP.fault =" and "metadataHTTP.result =" lines give the following error: "1119: access the fault of property may be undefined by a reference with static type mx.rpc.http.mxml:HTTPService." "" "»

In the documentation, it lists fault and the result as the HTTPService class events.  I guess you can't just define how you set a property to an event?  How are you?

When you specify event handlers in the ACE, you must use addEventListener():



  
    
  

If this post answers your question or assistance, please mark it as such.

Greg Lafrance - Flex 2 and 3 certified ACE

www.ChikaraDev.com

Flex / development, training, AIR and Support Services

Tags: Flex

Similar Questions

  • HTTPService in ActionScript

    I created this class

    Quote:

    package services
    {
    Import mx.collections.ArrayCollection;
    Import mx.rpc.http.HTTPService;
    Import mx.rpc.events.FaultEvent;
    Import mx.rpc.events.ResultEvent;

    / public class RSSService implements IService
    {
    private var _feeds:ArrayCollection;
    private var _titleChannel:String;

    private var _rssService:HTTPService;

    public void RSSService(url:String) {}
    _rssService = new HTTPService();
    _rssService.url = url;
    _rssService.useProxy = false;
    }

    public function send (): void {}
    _rssService.send ();
    _rssService.addEventListener (ResultEvent.RESULT, resultHandler);
    _rssService.addEventListener (FaultEvent.FAULT, faultHandler);
    }

    private void resultHandler(event:ResultEvent):void {}
    _feeds = event.result.rss.channel.item;
    _titleChannel = event.result.rss.channel.title;
    }

    private void faultHandler(event:FaultEvent):void {}

    }

    public function getResult (): Object {}
    If (_feeds == null) _rssService.send ();

    var result: Object = new Object();
    result.feeds = _feeds;
    result.titleChannel = _titleChannel;
    return the result;
    }

    }
    }
  • HttpService, data binding and graphics

    I'm sort of a newbie with flex - and that you have well understood the data binding in Flex. Hoping to get some advice here:

    I have a chart of the following type:

    < mx:ColumnChart
    ID = "myChart".
    dataProvider = "{srv.lastResult.X.Y}" "
    showDataTips = "true".
    width = '95% ' height = '95% ' >

    < mx:horizontalAxis >
    < mx:CategoryAxis
    categoryField = "First"
    / >
    < / mx:horizontalAxis >

    < mx:series >
    < mx:ColumnSeries
    xField = "First"
    yField = "Second"
    / >
    < / mx:series >
    < / mx:ColumnChart >

    and it is filled by a httpservice as follows:
    "< mx:HTTPService id ="srv"url =" 8180/hand "> "
    < mx:request >
    < param1 > one < / param1 >
    < / mx:request >
    < / mx:HTTPService >

    This method works well, aok.

    However, in my application, I need to be able to update this table dynamically.
    For this I use HttpService in actionscript code:
    service = new HTTPService();
    service. URL = "" 8180/hand "; "
    service.addEventListener ("result", Httpresultat);
    service.addEventListener ("default", httpFault);
    service. Send (Parameters);

    now, in the result handler...
    public void httpResult(event:ResultEvent):void {}
    var object: result = event.result;

    now here I don't know how to access the result object to bind it to the "myChart" above. Here pointers will be appreciated...

    }

    I don't think that any binding is required here. You can simply set the dataProvider to the new value. It would begin to show the new data.

    If you want really mandatory to make the update, then you just need to invoke the srv HTTPService himself again. Call srv.send () in your service of refreshing instead of create a new HTTPService. As myChart.dataProvider is already bound to srv.lastResult, she would get updated.

  • the click event listener smile ActionScript 3.0 works only once

    I am a newbie. I use actionscript 3.0 and I have a file .as separated with all my action script code. I have 2 buttons called myBtn1 and myBtn2 in my .fla including the base class file is two flash.display.SimpleButton.
    The event listener for myBtn1 (buttonClickHandler) always fire correctly. But the eventHandler for myBtn2 (textClickHandler) fires once and only if myBtn2 is the first button click. (I know that these event handlers and instructions switch sounds pretty ridiculous with a single element of each, but I removed the code).
    Why textClickHandler only seems to work once?
    Any help would be greatly appreciated!

    According to one of the Adobe Technical Notes sometimes the event mouse move is missed by the DisplayObject, thus, rather than attach the listener to the stage. Which works very well. So now instead of

    myBtn1.addEventListener(MouseEvent.CLICK,buttonClickHandler);
    myBtn2.addEventListener(MouseEvent.CLICK,buttonClickHandler);

    I have

    stage.addEventListener(MouseEvent.CLICK,buttonClickHandler);

    Read all about it:
    http://www.Adobe.com/cfusion/knowledgebase/index.cfm?id=69a2ae4b

  • Conversion of HTTPService in AS3

    One of the things I don't like Flex is to have make switch between xmxl and .so files that I work through the logic of my code. As a result, I want to convert all my tags HTTPService AS3. I don't see any point in writing the HTTPService in mxml, as there is no visual element that itself. So my question is this: can I simply use a loadVars object to manage my calls and returns to and from php (it even exists in AS3?), or should I use the HTTPService in AS3. If I should use the HTTPService in AS3, how I would write what follows?

    Thank you very much for looking.

    Hi SiHoop,

    In the next page of the documentation, please see the section "setting explicit way with HTTPService components:
    http://livedocs.Adobe.com/Flex/3/HTML/data_access_5.html

    Basically, there are 3 ways to pass the params to the server via HTTPService:
    1) links (in the link above, see section "Binding of parameter with HTTPService components"). This option applies mainly during instantiation through MXML HTTPService (i.e. ), not with the instantiation through ActionScript (as you do).
    2) in position send() compared to how defined on the method Server (for example myService.send (myText.text, myText2.text)
    3) in send() via the object with the properties that are defined on serverside method of param names, (for example
    var params: Object = new Object();
    myText.text = params.param1;
    params.param2 = myText2.text;
    myService.send (params);

    For option 3 above, please note that in page doc I had referenced my first answer, where their "parameters: the object" was being imposed on the signing of the definition of the useHttpService(parameters:Object) method, the parameters of the object were built in the calling code. Unfortunately, the latest version of this documentation does not call any code. (Just before I said last night, Amy had enough posted that he was "a kind of example of crap".) So, according to your requirement, you can create the object elsewhere and put it in, or you can build the object immediately before execution of send (params).

    BTW, here is a "quick start guide Flex for PHP developers" complete with the sample files. It does not cover the HTTPService via ActionScript execution. However, if you have not yet taken so, maybe he can help you with some examples of work to work with PHP backends for Flex.

    Please post back on so the above answers your question, and if you find it useful :-)

    Best regards

    g

  • Help with httpservice fault

    I'm new to flex (actionscript and really) and I'm having a problem with the program I am writing.
    My httpservice object is to launch a httpFault with a message that says:
    [MessagingError message = 'Destination 'destination of a xml file' does not exist or the destination has no channels defined (and the application sets any default channels.) ']
    I know that the xml file exists... I tried a few other establishments... honestly I don't know what means the channel bit (I looked at a few things from google on the same error and had an understanding of what has been said)

    I have attached my code, I'm not sure what I'm supposed to do.
    I'm trying to update a list with the data stored in the ArtistList class, which is my model, the php to http://localhost/bearcube2/artists.php output xml file... I also tried the xml files simply on the web and locally, I get the same error message

    I want to declare the httpService in actionscript and not the mxml because I intend to send user input more than GET requests, but I have not got that far yet.

    Sorry if I'm missing something simple, but I tried to find what im doing wrong for a while, and since I'm new to flex I tell myself that I do not understand how to use something.
    Thanks for any help

    Sorry I'm late, comes to be changed
    service.destination = url;
    service.url = url;

    Oops...

  • Post using Actionscript variables

    Hello

    I saw on the docs we might write HTTPService in Actionscript method. I finished the entire section based on the description of the method defined on the doc, but I'm having some trouble setting the variables to pass to the real service (mx:request as MXML).

    I need to know the real variable that is passed to the function, because I would like to reuse the information returned by the service for further changes. Because this information is not stored in the XML file, I wonder if someone can tell me what is the problem with the syntax below? Currently, all I get is this error:

    TypeError: Error #1009: cannot access a property or method of a null object reference.

    Anything is appreciated.

    "alice_data" wrote in message
    News:ge9nf1$1ai$1@forums. Macromedia.com...
    > Hi, Amy:
    >
    > Sorry, but I think I'm getting a bit confused at this point. I have
    > removed
    > var loader: URLLoader = new URLLoader();
    > loader.addEventListener (Event.COMPLETE, {function(event:Event):void}
    > trace ("done sending and loading:" + loader.data);
    > });
    > loader.load (request);
    > and represented the code and received the same error as before.
    >
    > Part of the problems with the error I get, is that I
    > not
    > set my settings correctly, but still when I tried to take the parameter
    > definition of the next line, he tells me I need an argument:
    ><>
    > label = "Submit" id = "mySubmitButton" click = "useHttpService ()" / >. " What should
    > I
    > put in parenthesis?
    >
    > The doc that I mentioned is to
    > http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?co
    > ntext = LiveDocs_Book_Parts & file = dataservices_099_15.html, but I think that my
    > main
    > problem here is that I do not know how to define variables and pass it
    > to
    > the real service and have to be handled internally through variables
    > Actionscript. Or, is what I'm trying to accomplish here not possible at all?

    Try to change this:
    private var request: HTTPService;
    TO
    private var request: URLRequest;

    I still think you get a lot of caveats you are ignorant (check the)
    tab). You must have obtained a double variable definition
    what you had.

    What you are trying to accomplish is possible, but do not pay
    pay attention to the warnings and errors Flex seeks to talk to you. They
    are your friend.

  • Unload and stop the swf from scene

    Hello

    I am a newbie in Flash and Actionscript. I need to give links to about 20 files swf via the menu.swf buttons. I am able to give links. But when I come back by clicking the HOME button held in the newly loaded swf audio files are always played in the background.

    Yes, there are audio files playing in the back for each slide in the new FSV. Then click the link even menu.swf again once the files are played with the old incomplete file. It's really intense.

    I need to unload the scene completely when I return to menu.swf by clicking the HOME button on one of the 20 categories.

    I used unloadAndStop but it does not. I hope I'm mistakes of committing to a place but could not provide.

    Need help!

    FOR THE HOME BUTTON:


    var _content:Loader = new Loader();

    function loadContent(content:String):void {}

    If (_content! = null) {}

    _content.unloadAndStop (true);

    removeChild (_content);

    _content = null;

    }

    var loader: Loader = new Loader();

    Loader.Load (new URLRequest (content)); -> > > > I don't really know what to put in this :-(

    _content = addChild (loader) like charger;

    }

    Home_Button.addEventListener (MouseEvent.CLICK, home);

    function home(event:MouseEvent) {}

    _content.unloadAndStop (true);

    var homeSWF:URLRequest = new URLRequest ("demo.swf");

    _content. Load (homeSWF);

    addChild (_content);

    }

    MENU.swf BUTTON

    var loader: Loader = new Loader();

    Category1_Button.addEventListener (MouseEvent.CLICK, category 1);

    function category1(event:MouseEvent):void {}

    var Category1SWF:URLRequest = new URLRequest("Category1.swf");

    Loader.Load (Category1SWF);

    addChild (loader);

    }

    I think that there is a question of terminology.

    your main swf is the SWF that is embedded in your html page.  It is the first swf to display, and it can not be unloaded using actionscript.

    It must contain the loader, the only case of Loader, you need.

    This main swf may or may not be main.swf.

    in your main swf file, you must use:

    /////////////////////////////////

    var loader: Loader = new Loader();

    addChild (loader);

    function loadF(fileS:String):void {}

    {if (Loader.Content)}

    loader.unloadAndStop ();

    }

    Loader.Load (new URLRequest (fileS));

    addChild (loader);

    }

    function unloadF (): void {}

    {if (Loader.Content)}

    loader.unloadAndStop ();

    }

    }

    /////////////////////////////////////////

    do not change anything between the lines.

    ----------------------------------------------------

    your main SWF, if you want to load "catgoryxyz.swf", use:

    loadF ("categoryxyz.swf");  This argument in this line, you can and will change

    you main swf, if you want to unload all that is been loaded (and seem to go back to your file main swf), use:

    unloadF();

    ---------------------------------------------------

    Since the script a swf loaded (as categoryxyz.swf) principal, if you want to load "categoryabc.swf", use:

    MovieClip (this.parent.parent) .loadF ("categoryabc.swf");  the argument in this line, you can and will change

    If you want a swf to unload himself (and seem to go back to your main swf file), use:

    MovieClip (this.parent.parent) .unloadF ();

    -----------------------------------------------------------------

  • count the time in millisecond when datagrid loading data

    Hello world

    IM newbie in Flash and ActionScript things.
    I want to count how many time the dataGrid load all data.
    I try his code:

    var Date1:Date = new Date;

    xmlLoader. addEventListener () Event. ( FULL, LoadXML ();

    xmlLoader. load ()new URLRequest ()""http://localhost/final/Flash/DB-Single/get_db.php"" () (); "

    date2 var :Date = new Date());

    trace ( ) date2. valueOf () - date1. valueOf () );

    trace ( ) date2. getTime () - date1. getTime () );

    loadTimeTB. text = "Loaded:"+ ()date2. "." valueOf ()) - date1. valueOf ()) +" Milliseconds";

    but the result is 1 or 0 milliseconds. I think that its a little weird. because the dataGrid load takes longer to 1 millisecond.
    can someone help me? or give me some ideas?

    Thanks before guys.


    --desMO-

    It's because you run the code one after the other. I'm surprised it gets never as high as 1.

    You have to put the date of the first right after you run the load command, which is what you have.

    But you have to put the second track within the COMPLETE event management service. I see you have assigned, but I do not see where the LoadXML function is called. BTW, it is usually good to begin the names of class with capital letters, but methods (functions) should start with lowercase letters.

    I think you can also do a little easier if you're using getTimer() instead of the class Date.

    xmlLoader.addEventListener (Event.COMPLETE, loadXML);

    xmlLoader.load (new URLRequest ("http://localhost/final/Flash/DB-Single/get_db.php"));

    var startTime:Number=getTimer();

    function loadXML(e:Event) {}

    loadTimeTB.text = "Loaded:" + (getTimer () - startTime) + "milliseconds";

    }

  • HTTPService request and the Actionscript questions

    Hello

    I don't know if anyone on the list could tell me what I'm trying to do here is possible. The scenario is that I have here a HTTPService which functionally works fine, but I want to do the rest of the processing in-house, instead of PHP (that of the HTTPService do the job)

    I wanted to make a function call to the HTTPService and then manage the variables I get from PHP, which currently I just use something like {simulation.lastResult.service.number}. If I want retrieve this value directly and do some manipulations of calculation with it in Actionscript, how can I retrieve the value of the above without having to rewrite my HTTPService? (Or, what is more effective?)

    Note: I am currently using PHP to do the same thing, but I would like to do in-house without hoarding my remote server.

    Any help is appreciated.

    Here's the HTTPService I:

    Try this example. It uses an XML file on my site that the data source and does not use PHP for any treatment, but it gives the basics.


    http://www.Adobe.com/2006/mxml '.
    layout = "absolute" >

    Import mx.controls.Alert;
    Import mx.rpc.events.FaultEvent;
    Import mx.rpc.events.ResultEvent;

    define your variables to the instance level and make sure that they are can be related
    [Bindable] private var totalBuy:int = 0;
    [Bindable] private var totalSell:int = 0;
    [Bindable] private var remaining: int = 0;

    private void resultHandler(e:ResultEvent): void {}
    This returns XML data your data may be different.
    You will see what the returned XML. Your code will change here
    According to what is returned.
    var xmlLst: XMLList = new XML (e.result) .children ();
    Alert.Show (xmlLst.toXMLString (), "Return Values");
    totalBuy = xmlLst [0];
    totalSell = xmlLst [1];
    remaining = totalBuy - totalSell;
    }

    private void faultHandler(e:FaultEvent): void {}
    Alert.Show (e.message.toString (), "Error");
    }
    private void runService(): void {}
    dataService.send ();
    }

    ]]>

    <>
    ID = "dataService."
    ' URL =' http://www.siteorderly.com/xml/costData.xml '
    resultFormat = "xml".
    result = "resultHandler (Event); »
    Fault = "FaultHandler (Event); » />







  • Newbie question - using Tween via ActionScript

    Let me start by saying that I am completely new to Flash, so I won't be at all offended if formulate you your answer as if I was eight years old. In fact, I'd quite probably happy.

    I'm trying to recreate a simple Flash animation that someone did for me in the past. I thought I had an idea about what was going on in it, but it seems that there is a piece that miss me. Basically, there are three images (in fact the video clips) covered buttons (also video clips). When a button is clicked, the image below fades into view. There are also three other buttons, one per image, causing this same thing happen.

    So, I recreated the original file using new images. I created each instance of each clip that was present in the original file and named each of them and set the properties to match. Then I copied the original to the new ActionScript code and ran the debugger. The code is as follows:

    Import mx.transitions.Tween;
    Import mx.transitions.easing. *;
    txt1._alpha = txt2._alpha = txt3._alpha = 0;
    click1.onRelease = pclick1.onRelease = Function)
    {
    click1._visible = pclick1._visible = false;
    var xScaleT:Tween = new Tween (exp1, "_alpha", Strong.easeOut, 0, 100, 2, true);
    var xScaleT:Tween = new Tween (txt1, "_alpha", Strong.easeOut, 0, 100, 2, true);
    }

    click2.onRelease = pclick2.onRelease = Function)
    {
    click2._visible = pclick2._visible = false;
    var xScaleT:Tween = new Tween (exp2, "_alpha", Strong.easeOut, 0, 100, 2, true);
    var xScaleT:Tween = new Tween (txt2, "_alpha", Strong.easeOut, 0, 100, 2, true);
    }

    Click3.onRelease = pclick3.onRelease = Function)
    {
    Click3._visible = pclick3._visible = false;
    var xScaleT:Tween = new Tween (exp3, "_alpha", Strong.easeOut, 0, 100, 2, true);
    var xScaleT:Tween = new Tween (txt3, "_alpha", Strong.easeOut, 0, 100, 2, true);
    }

    When I ran this film, I received five of the error "there is a conflict with the xScaleT definition in the internal namespace.

    Googling this error led me to believe that it was because of all the declarations with the same name (despite the fact that this same error appears when the original film is run), so I changed the xScaleT1, xScaleT2, etc. This got rid of the 'conflict' errors, but I now get:

    1172: definition mx.transitions:Tween could not be found.
    1172: definition mx.transition:easing could not be found.

    .. .and then a bunch of type and the property not found error I guess stem out of its inability to find the two definitions above.

    Why don't happen when I run the original film and how what to do to fix? Is there any statement or class code, I missed the copy of the original? All advice is appreciated. Thank you.

    Make sure that your publication settings are not defined for AS2 and AS3.

  • ActionScript Newbie needs help!

    Hi everyone and everybody-

    This should be fairly simple, but I don't know where to start. I need to set up some actionscript that load randomly one images in my library every time the site is. I have the link assigned to each picture (currently they are IMG1 through IMG10), but I don't know how a.) Download Flash to recognize that these are the photos I want to deal with and b). randomly to load one each time the site is opened (or the hand page is revisited, or something else).

    If you can help me, it would be greatly appreciated!
    Thank you!

    :

  • Newbie is always be stupid! ActionScript for a button to a URL is not link?

    Don't know what I'm doing wrong now.  I coded the frame as below, but when I publish it he's not linking?  Any suggestions? (obviously a false link here, but use a link that actually works!)

    Stop();

    var getPaypalBoostaboiler:URLRequest = new URLRequest ("http://www.addressgoeshere.co.uk");

    -Download URL-------.

    paypal_boostaboiler.addEventListener (MouseEvent.Click, boostaboilerBuy);

    function boostaboilerBuy(event:MouseEvent):void {}
    navigateToURL (getPaypalBoostaboiler);
    }

    Hi Ned - you today be my Savior!

    I was just to publish, and then by opening the swf file.

  • Help micro. ActionScript newbie

    Hello, I was wondering if anyone can point me in the right direction. For my fmp, I am creating a speech animation. I've tried a few things and so far I have a few feasible actionscipt. The problem is I do not know where to go form here, need google or even look for. I'm trying to find a way;

    -Find the value when he said. I saw what makes when someone talks he gives you a number that corresponds to the value of that particular level of her speaks volume, does that make sense?
    -To activate a specific when clip this value is reached. (so say it the voice of the user visits 70 at the start of the animation)
    -To set the other clips of film to fade and exit where their selected value is exceeded. So say you're talking who is worth 30, when you speak up to say 40, then 30 animation would have melted, while 40 animation would have melted in.

    Sorry if this does not really make sense, I'm not very good when it comes to explain what I need. Also if anyone knows a good tutorials for ACE, then I would be very grateful. See you soon.

    What you might try sets up a timer to check the activity level all the secondes.5 and then react according to the value that you get.

    See you soon,.
    FlashTastic

  • A loop of HTTPService

    Hello, a newbie here. I would like to know how to make a loop with httpservice calls inside. I have a table called storyID, let's say:
    storyID = [4542,2354,2354,1234,7653];
    StoryID is not always long 5 elements, it varies.

    The appeal of httpservice url looks like:
    ttp://API.WebService.com/article/ h storyID
    where storyID is one of the items in the named table.

    So, I want to do a loop that goes through all the elements of the array storyID and make an httpservice call on each iteration with the corresponding storyID.

    Using the repeat does not work for me. I think the only way is to make an actionscript call. Can someone give an example, please. Thank you.

    Well, finally got it work. I couldn't use s1.send (id); because I use the api requires the id to do part of the url itself, not as a parameter. Example:
    URL = "ttp://api.webservice.com/article/storyID?appkey=myApp:".
    and is not:
    URL = "ttp://api.webservice.com/article?story=storyID h, appkey is myApp"

    I don't know if it's possible with the format s1.send (id) or not, but if it's possible, I still don't know how to do it.
    But anyway, I found a very useful page on the livedocs.

    With the example on the page dip as a guide, I managed to get to this:

    <>
    ID = "httpStoryDetails".
    resultFormat = "e4x".
    result = "httpStoryDetailsHandler (Event); »
    Fault = "httpFaultHandler (Event); »
    showBusyCursor = "true".
    />

    private function getStoryDetailsXML (): void {}
    for (var j: uint = 0; j< storyidarray.length;="">
    httpStoryDetails.url = 'h ttp://api.webservice.com/article/' + storyIDArray [j] + "?" appkey = myApp ";
    var httpStoryDetailsCall:Object = httpStoryDetails.send ();
    httpStoryDetailsCall.marker = "call" + j;
    }
    }

    private void httpStoryDetailsHandler(event:Object):void {}
    var httpStoryDetailsCall:Object = event.token;
    for (var j: uint = 0; j< storyidarray.length;="">
    If (httpStoryDetailsCall.marker == ('call' + j)) {}
    myXML.story[j].@title = httpStoryDetails.lastResult.story.title.text ();
    }
    }
    }

    That's all. I hope this helps other people have this problem. And by the way, it's really hard to show the code read on this forum. Adobe should do something.

Maybe you are looking for