Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6139511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:59:56+00:00 2026-05-23T17:59:56+00:00

I’m using this simple code to retrieve a value from a PHP script: package

  • 0

I’m using this simple code to retrieve a value from a PHP script:

package 
{
    import flash.display.MovieClip;
    import flash.net.URLLoader;
    import flash.net.URLVariables;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    //
    public class URLTest extends MovieClip
    {
        //
        var scriptLoader:URLLoader;
        //
        public function URLTest()
        {
            scriptLoader = new URLLoader();
            scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
            scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
        }
        //;
        public function handleLoadSuccessful($evt:Event):void
        {
            trace("Message sent.");
            trace($evt.target.data);
        }
        //
        public function handleLoadError($evt:IOErrorEvent):void
        {
            trace("Message failed.");
        }
        //
        public function sendLoad(variable):void
        {
            var scriptRequest:URLRequest = new URLRequest("http://mydomain/myapp/my.php");
            var scriptVars:URLVariables = new URLVariables();

            scriptVars.var1 = variable;

            scriptRequest.method = URLRequestMethod.POST;
            scriptRequest.data = scriptVars;

            scriptLoader.load(scriptRequest);
            trace(scriptLoader);
        }

    }

}

If you look at the URLTest constructor you’ll find I initialize the listeners of an instance of URLLoader.

Is it a better practice to declare a method initListeners and call it everytime I call sendAndLoad? As a consequence, would it be a better practice that of removing the listeners inside the handleLoadError and handleLoadSuccesful methods? Are listeners cpu-intensive?

Btw, I don’t understand why this question “appears to be subjective”, since we’re talking about performances, not programming style.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:59:56+00:00Added an answer on May 23, 2026 at 5:59 pm

    As your class is designed to be able to make multiple calls to the same webservice, I would definitely go for option 2. Consider this:

    var loader:URLTest = new URLTest();
    loader.sendLoad("a");
    loader.sendLoad("b");
    

    Now, if you re-use the same URLLoader for both calls, there is no way you can know which COMPLETE event is going to correspond to which call.

    To solve this issue you would create a URLLoader (+ event listeners) for each call and put it in an Array to be able to identify it. When an answer comes from the server – be it a COMPLETE or an IOERROR – you can remove the event listeners and remove the identified URLLoader (the one that matches event.currentTarget) from the Array.

    The performance issue is trivial here. There will be no performance hit for creating a bunch of event listeners as long as you remember to remove them when you’re done with them. Otherwise the corresponding URLLoaders will not be garbage collected and will keep piling up in memory.

    On a side note: there’s absolutely no reason to extend from MovieClip. If you want your class to dispatch events, just extend EventDispatcher.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.