0

I'm trying to reuse the HTTPService object in a flex app but I'm running into a problem. In the handler for ResultEvent.RESULT I'm removing the listener, but it isn't removed. I've have to catch the asyncToken from send() and attach a new property so I know what it's supposed to do in the handler.

I've set up an example here: http://www.152.org/flex/
You can right-click and view source.

Has anyone else run into an issue where listeners aren't removed? Should HTTPService not be reused?

3 Answers 3

3

You cannot remove event listeners added in the mxml tag. livedocs says:

You can remove only event listeners that you added with the addEventListener() method in an ActionScript block. You cannot remove an event listener that was defined in the MXML tag

Define your HTTPService objects in actionscript (creationComplete of the app) and add event listeners using addEventListener method so that you can call removeEventListener on them to reuse.

Sign up to request clarification or add additional context in comments.

5 Comments

That's the approach I'm currently using. Events aren't removed when I call removeEventListener.
Read it again. Event listeners added thru mxml cannot be removed using removeEventListener. Period.
Now I understand what you mean. I thought you meant if you used something inline on an MXML tag. Since I'm creating the HTTPService call in a .MXML file I can't use removeEventListener. I'll try that on monday.
Worked like a charm. I moved the HTTPService requests out to a wrapper file and I was able to remove the eventListeners. Thanks for your help.
This is a solution to a bug that exists in flex 3.4. It works fine in previous versions.
0

I came accross this problem today on an application that had been working well for several months. After serval hours of debugging, I found out that a recent upgrade in my flex compiler settings from 3.1 to 3.4 was the culprit. For now I have restored 3.1 as the compilation environment in order for my project to continue working.

In my opinion this is a major bug introduced sometime after Flex 3.1, I hope adobe fixes it soon. I reuse HTTPService all the time all over my code and this bug makes version 3.4 not workable for me.

Hope this helps.

3 Comments

good to know this know this was a bug and not a problem with my code. i'll have to update this example to reuse the service and submit it as a bug to adobe. thanks.
You are correct. I tested a tagged version of my code with flex 3.0 and it worked perfect. This is a new bug in the code. I'll submit this to adobe. Thanks for your help.
I've reported this as a bug to adobe. bugs.adobe.com/jira/browse/SDK-24847
0

There is no guarantee that the event listener will be removed. Try making it a weak event handler when installing it on your object. There's a better chance that Flex's GC will free this when you remove it.

2 Comments

I tried creating a weak reference and it's still not removing them. .addEventListener(ResultEvent.RESULT, populateTilelist, false, 0, true); .removeEventListener(ResultEvent.RESULT, populateTilelist, false);
As I said, it's up to the VM to do GC. That's the right approach. However, the AS3 VM apparently finds some reference still pointing to this resource and hence does not remove the event handlers. Time to check the rest of the code, I believe?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.