Can't remove event listener from Image

I'm clearly missing something and would appreciate some help.  I'm trying to run an event handler when an Image completes loading,  then remove the handler so that it won't  run again should the image be reloaded later.
The problem that I'm having is that the event handler simply wont' go away, despite calling removeEventListener on the Image object.
The following example demonstrates the problem (the example doesn't actually do anything useful...it's just the shortest example to demonstrate the problem).  (To run the  app, you'll have to provide any ol' JPEG file named "myImage.jpg" in the "src" directory of your project).
What I expect to happen is :
     1) on startup, the image loads and loadComplete() runs.
     2)  loadComplete removes the event Listener so that subsequent re-loads won't re-fire the handler.  I only want the handler to  run once.
     3) "loadComplete" shoudl  be displayed in the Debug console.
     4) A button click should display only "Changing  Image" in the Debug console
What I get instead is that the loadComplete handler isn't  removed, and every  time I click the button, loadComplete runs when the image is re-loaded   (i.e., every button click results in both "Change Image" AND "loadComplete"  being displayed in the Debug console).
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Image width="655" height="181" source="myImage.jpg" id="myImage" autoLoad="true" scaleContent="true" complete="loadComplete()" x="100" y="100"/>
    <mx:Button x="100" y="341" label="Button" click="click(event)"/>
    <mx:Script>
        <![CDATA[
            private function loadComplete():void
                trace ("loadComplete");
                myImage.removeEventListener("complete", loadComplete);
            private function click(evt:Event):void
                trace ("Changing Image");
                myImage.load("myImage.jpg");    //  Reload same image; it's just an example
        ]]>
    </mx:Script>
</mx:Application>

Hi,
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, even if it was registered using a call  to the addEventListener()method that was made inside a tag attribute.
Check this page for reference.
http://livedocs.adobe.com/flex/3/html/help.html?content=events_05.html
You can modify the code a bit a get it working
<mx:Image width="655" height="181" id="myImage" scaleContent="true"
          x="100" y="100"
          creationComplete="myImage_creationCompleteHandler(event)"/>
private function myImage_creationCompleteHandler(event:FlexEvent):void
     myImage.addEventListener("complete",myImage_completeHandler);
     myImage.load("myImage.jpg");
private function myImage_completeHandler(event:Event):void
     myImage.removeEventListener("complete",myImage_completeHandler);

Similar Messages

  • Remove event listener from loaded external swf

    I have a main movie timeline that loads an external swf. When I unload the swf from the main timeline I get an error from this:  my_FLVPlybk.addEventListener(VideoEvent.COMPLETE, vidEnd);
    is there any way to remove the event listener from the loaded swf from the main timeline?
    THANKS!

    if you're publishing for fp 10+, use unloadAndStop() applied to your swf's loader.  that has a fair chance of solving the problem.
    if that fails, you should explicitly stop my_FLVPlybk.

  • Removing event listener from a button.

    I've added a "click" event listener to a button, but I'd like to remove it once the button is clicked, so it's not active/clickable any longer. Here's the basic code:
    sym.$('button').click(function(){
         //here I need to make this button not clickable any longer
    Thank you.

    one way...
    sym.$('button').click(function(){
         //here I need to make this button not clickable any longer
         // do smething here then unbind click handler
                sym.$('button').unbind( "click" );
    unbind documentation here.
    hth
    Darrell

  • How can I remove events from my iPhone. I want to delete all the events from my iPhone.

    how can I remove Events from my Photo in iPhone

    Connect to computer iTunes and uncheck under Photos > Events then do a sync.

  • How can I remove people tags from MULTIPLE images in Organizer 13?

    How can I remove people tags from MULTIPLE images in Organizer 13?  The strategy for removing keyword tags does not work. It appears that keyword tags and People tags are considered something completely different in 13.  I highlight multiple images, right click, and under keyword tags it says there are no keyword tags. There does not appear to be an option for people or other tags. Can anyone help? It is going to take literally hundreds of hours for me to do this one photo one tag at a time.  ??

    Comp. 792 wrote:
    Hi, my linked images all have dashed lines at the bottom of the images. I searched for an answer and someone said to add:
    img a {text-decoration:none:}
    to the end of my CSS,
    That CSS is complete nonsense. The correct way to remove borders from around links is here: http://forums.adobe.com/thread/417110.
    If you want to get rid of dotted lines, they are almost certainly caused by the outline property. However, outlines around links are there for a reason: it provides a visual "you are here" clue to people who navigate the web with the keyboard, either through preference or because of disability. You shouldn't remove the dotted outline without providing a different visual clue.

  • Removing an event listener from buttons

    Hi.
    I´d like to know if it´s necessary to remove event listeners from buttons.
    I know it's good practice to remove event listeners when its use is over.
    But it´s necessary to remove event listeners for buttons as well?
    Thanks

    it's necessary if you want to ready your buttons for gc.

  • How can I remove credit card from itunes account?

    How can I remove credit card from itunes account?

    I'm not home right now, so don't have iTunes here. I am basing this on having to do this a few days ago, as well as pictures from Google Images, so things may have different names now...
    Store (dropdown at top of iTunes screen)>View my account>Edit Payment Information>In the list of types of credit cards, the one at the far right says "None." Click that.

  • How can I remove all photos from my iphone?

    How can I remove all photos from my iphone?

    Hi pjdemeo,
    I understand you want to delete all of the photos from your iPhone.  As a precaution, I would suggest importing the photos and videos from your iPhone into your computer.  This will give you a backup for the images, and after import you will be asked if you want to delete the photos.
    Import photos and videos from your iPhone, iPad, or iPod touch to your Mac or Windows PC - Apple Support
    https://support.apple.com/en-us/HT201302
    The iPhone User Guide has instructions for deleting photos directly from the device:
    Organize photos and videos - iPhone
    http://help.apple.com/iphone/8/#/iphf14943e
    Delete a photo or video from Photos. Tap the Photos tab, tap the photo or video, tap , then tap Delete Photo or Delete Video. Deleted photos and videos are kept in the Recently Deleted album on iPhone, with a badge showing the remaining days until the item is permanently removed from iPhone. To delete the photo or video permanently before the days expire, tap the item, tap Delete, then tap Delete Photo or Delete Video. If you use iCloud Photo Library beta, deleted photos and videos are permanently removed from all iOS 8.1 devices that use iCloud Photo Library beta with the same Apple ID.
    Cheers,
    - Judy

  • Can't remove old episodes from iPod sine Update!

    I have a Shuffle & usually carry 3-5 episodes each of 8-10 different podcasts.  Sine installing the new iTunes for Windows, I can't remove old eps from the device, & it's a total crapshoot as to which NEW episodes the system will allow me to click on!!
    HELP!!!!!!

    There are several ways to add podcast episodes to the shuffle, so please correct my assumptions in a reply.  How you add podcasts determines how you remove them.  I can't tell how you do it from the info you provide.
    It sound like you may add podcast episodes manually (drag and drop to iPod).  If you do, and your shuffle is 3rd or 4th (current) gen, you should consider doing it using automatic syncing, by putting podcast episodes on a playlist (in your iTunes library and syncing it to the shuffle).  Update the playlist at any time, by adding new podcast episodes and removing old ones (the shuffle does not need to be connected).  Put the podcast episodes in desired order.  iTunes automatically updates the shuffle the next time it is connected (or by clicking Sync if already connected).  On the shuffle, you can listen to podcasts from that playlist, and hear episodes from different podcasts consecutively, in the desired order.
    When you remove podcast episodes manually, is this the way you do it?  Again, this is for 3rd or 4th gen shuffle.  Select the shuffle in iTunes, so that you see its "management" screen.  In the sidebar, under On My Device, click Podcasts.  To the right, the podcast episodes currently on the shuffle are shown.  Select the one(s) you want to remove an press Delete on the keyboard.

  • How can we remove the commas from the Formula value in SAP BW BEx query

    Hi All,
    How can we remove the commas from the Formula value in SAP BW BEx query
    We are using the formula replacing with characteristic.The characteristic value needs to be display as number with out commas.
    Regards
    Venkat.

    Do you want to remove the commas when you run the query on Bex Web or in RSRT?
    Regards

  • How can i remove a card from iTunes ?

    How can i remove a card from iTunes ?

    If you want to remove a credit/debit card from your account then on your computer's iTunes you should be able to edit your payment info by going into the Store > View Account menu option and logging into your account, and on your account's details page there should be a payment link.  If you are doing it on your iOS device then tap on your id in Settings > iTunes & App Store and tap on 'View Apple ID' on the popup and log into your account  - that should also give you a payments link on your account's page.
    Changing payment info : Change or remove your payment information from your iTunes Store account (Apple ID)
    If you don't get the 'none' option on the payment details screen : Why can’t I select None when I edit my Apple ID payment information?

  • HT202667 how can I remove credit card from apple id ?

    i don't want to use apple id with credit card anymore i purchased enough apps for my apple device so now i wanna remove it so how can i remove credit card from apple id

    On your computer's iTunes you should be able to edit your payment info by going into the Store > View Account menu option and logging into your account, and on your account's details page there should be a payment link.  If you are doing it on your iPhone then tap on your id in Settings > iTunes & App Store and tap on 'View Apple ID' on the popup and log into your account  - that should also give you a payments link on your account's page.
    Changing payment info : http://support.apple.com/en-gb/HT1918
    If you don't get the 'none' option on the payment details screen : http://support.apple.com/en-gb/TS5366

  • How can I remove some themes from Keynote??

    How can I remove some themes from Keynote??

    What a co-incidence... I just deleted those same goodies. They were in /Library/Application Support/Keynote-folder on my machine. I just deleted the whole folder, cause there seemed to be nothing more but those downloaded files. And Keynote worked great afterwards. There seemed to be another folder for iWork09, which is not to be removed.

  • HT5622 We have two iphones with the same Apple ID. Since I installed iOS this morning I have started receiving all my sons texts and when I send him a text it is delivered to both of us. How can I remove my phone from the joint Apple ID and remove myself

    My son and I both have iphones with the same Apple ID. Since I installed iOS this morning I have started receiving all my sons texts and when I send him a text it is delivered to both of us. How can I remove my phone from the joint Apple ID and remove myself from finding out what he is up to during Freshers week!

    You have to use a different Apple ID for your son.
    Read this note:
    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family
    still valid for ios 7

Maybe you are looking for