Best place to put the event listener?

Hey there!
I am loading several images using a loop. My question is, would it be better to put the "contentLoaderInfo.addEventListener(Event.COMPLETE..." in the loop so it loads the compelte handler each time it goes through the loop, or is it fine to put it outside of the loop at the end?
Also, could you explain the reason for your answer?
Thanks!

alright. here is what I have:
          public function placePictures():void {
               private var imageURLs:Array = ["images/1.jpg","images/2.jpg","images/3.jpg","images/4.jpg",
                                     "images/5.jpg", "images/6.jpg","images/7.jpg", "images/8.jpg",
                                     "images/9.jpg"];               
               var ba:Array = new Array();
               ba.push(b1,b2,b3,b4,b5,b6,b7,b8,b9);
               for(var i:uint=0;i<ba.length;i++) {
                    trace(name + ba[i]);
                    ba[i].name = i;
                    imageLoader = new Loader();
                    imageLoader.load(new URLRequest(imageURLs.shift()));
                    //HERE...///////////////////////////////////////////////////////
                    //imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
                    imageHolder = new Sprite();
                    imageHolder.graphics.lineStyle(5, 0x000000, 100, false, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle.MITER);
                    imageHolder.graphics.drawRect(0, 0, 180, 100);
                    imageHolder.addChild(imageLoader);
                    if (i<=2){
                         imageHolder.x = 250 + i * 300;
                         imageHolder.y = 0;
                    } else if (i<6) {
                         imageHolder.x = 250 - 900 + i * 300;
                         imageHolder.y = 200;
                    } else {
                         imageHolder.x = 250 - 1800 + i * 300;
                         imageHolder.y = 400;
                    ba[i].y = 230;
                    ba[i].x = 0;
                    ba[i].buttonMode=true;
                    ba[i].addChild(imageHolder);
                    peHolder.addChild(ba[i]);
                    ba[i].addEventListener(MouseEvent.CLICK, onButtonClick);
               //OR HERE...//////////////////////////////////////////////////////////////
               imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
          public function loadCompleteHandler(e:Event) {
               trace ("load complete handler loaded");
               imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadCompleteHandler);

Similar Messages

  • The best place to put the global parameter

    hello:
    i am now studying the petstore1.3,and find that the global parameters are kept in the servlet context,i wonder if it is a good solution.in my project,i seldom use the servlet context,session context etc,i feel more like to put the global parameter in a singleton that is loaded when the app is started. i don't know where is the best place to put the global parameter,servlet context or singleton?

    thanks for your answer.
    1 do your mean that the singleton can be shared among the different "war"
    packages if both of them are within the same jvm?if yes,must they be in the
    same "ear" package?
    2 if my app is deployed in the weblogic cluster environment,which one can be
    shared? singleton or servlet context?

  • Where is the best place to put custom functions?

    Hi,
    I have a composition which has a number of symbols. I have to call some custom methods externally and was wondering where is the best place to put the custom methods?
    I have seen posts that I should put the code in the CompositionReady event of the stage but I would like to put it a bit closer to the symbol.
    Is this the best place?
    Sham.

    Here is a case:
    It's a good idea if you well understand global and local variables.
    About complete event, you are right.

  • Where is the best place to put cfqueries?

    Where is the best place to put cfqueries, in the <head> </head> or before the html tag? Thanks

    So before the doctype tag? Thanks
    I just doesn't really matter.  the doctype, head, body, etc only matter to the browser; the CF tags only matter to CF.  The browser doesn't see the CFML, and CF doesn't care about the mark-up one bit: it just ignores it.
    The best place - as I said - is not in the same file at all.  But if you insist on slapping your business logic in with your display logic, then the only consideration is that you need to set your variables before you use them.  Other than that: it simply doesn't matter.
    One consideration you might make is - even if it's all thrown into the same one file - at least separate the file itself into sections: have all your CFML code that gets your data at the top, and try to limit the CFML you have mixed in with the mark-up, eg: limit it to stuff like loops and conditionals.
    But, seriously, separate your concerns.  Dan's pretty much just wrong when he said it's over-engineering. It's just sloppy to not to write tidy, well-maintained, well-organised code.
    Adam

  • How can I check if a function is or is not called from the event listener? in Flash CS4 (AS3)

    Hi,
    I came across a little problem.
    I put an event listener inside a for loop and the for loop inside a function.
    I want the for loop to end as soon as the event listener inside the for loop calls its function.
    Here is the general code for a better picture.
    Code:
    this.addEventListener(Event.ENTER_FRAME, function#1);
    function function#1(event:Event):void{
              if(something is true){
                        for(var i = 0; i < numOfmy_mcs; i++){
                                  this["my_mc_"+String(i)].addEventListener(MouseEvent.CLICK, function#2);
    function function#2(e:Event):void{
    //do something cool here
    Thank you for any help!

    kglad wrote:
    that for-loop (if it executes), defines listeners for interactive objects.  that will complete long before any object is clicked.
    Well yes but it does it again and again (frames per second times seconds = number of times it goes through the code if i'm not mistaken), because it is inside a function, and through testing i found out that it works like this:
    Example:
    there are 5 my_mc's in my project: (my_mc_0, my_mc_1, my_mc_2, my_mc_3, my_mc_4)
    if i click my_mc_0 function#2 is called and executed. BUT only after the loop finishes (i know this from tons of testing)...which is unnecessary since you cannot click two places at once. This might not be a problem in this example because i am only using 5 my_mc's buy if i use 500000000 my_mc's it would make a lot of difference.
    is there a way to stop the loop if the function is called?
    ...maybe there is a better way to write it, the only alternative i know that works is if i manually write every single listener and this also is logical in this example but as i said next to impossible if the numbers get bigger.
    -Note
    I didn't specify this earlier but function#2 makes the if statement false so it wont jump back into it.
    Thank you for the help I really appreciate it!
    3rd edit...don't know what's wrong with me

  • Best place to put cffunctions?

    Hi All,
    I've created a cffunction which I need to access more or less from every page. Where is the best place to put it?
    Can I put it in the Application.cfc? If yes how, and how can I call it from a page?
    Thanks!

    ianskinner wrote:
    Just realize if you are putting the function into the session scope, each and every user is getting an entire copy of the function in the server's memory.
    Depending on the purpose of the function and how you are using it, this may or may not be a lot of memory used up unnecessarily.
    If the function is something that each user does not need their very own copy then it might make more sense to put it into the application scope.  Then there would be one copy of the function that all users utilize.  You could, of course, do that in the OnApplicaitonStart() function of the Application.cfc.
    I agree with Ian that Dan's advice in this case is suboptimal.
    The only things that should go in the session scope are things that specifically related to the session.  Which is not the case here.
    Adam

  • 2 HD laptop setup - Best place to put Catalog, Cache, and Images??

    If I have two 500GB 7200rpm hard drives in my MBP, what is the best place for LR3, the catalog/previews, ACRcache, and the image files themselves?
    SATA3 connection for both HDs
    Should the boot drive hold the app and cache, while the second drive hold the files and catalog?
    Should the catalog and cache always stay on the same drive?
    Does it matter at all where the image (raw) files sit?
    Thanks!!

    I'd just keep the images on a different drive with a 2 internal drive setup.

  • HT203175 I downloaded two videos from itunes into Media Go and I can't play or transfer them to my Walkman. Please help. I'm new at this and haven't a clue as to what I should do. Is Media Go the wrong place to put the videos? Thanks. Earl G.

    I downloaded two videos from itunes into Media Go and I can't play or transfer them to my Walkman. Please help. I'm new at this and haven't a clue as to what I should do. Is Media Go the wrong place to put the videos? Thanks. Earl G.

    I was able to transfer songs, but not the videos. You, too? Earl. G.

  • Mail under Mavericks_keep failing the right place to put the cursor to rewrite a word

    Mail under Mavericks_keep failing the right place to put the cursor to rewrite a word.
    When I´m writing a mail, if I see an error and want to rewrite a word or a sentence, it´s almost impossible to put the cursor at the right place to rewrite what I need. Most of the times I´ve to erase entire sentences and write everything again.
    Any suggestion for this new problem under Mavericks? Please.
    Thank you.

    https://discussions.apple.com/message/23650743#23650743
    This solved my problem.
    Thanks.

  • Best place to find the most authentic information

    Best place to find the most authentic information about plans, insurance companies, eligibility, navigators and even the Exchange. Most often, people are unaware that they are eligible for government sponsored coverage and end up buying private and costly health plans. But when a resident accesses the Exchange, he is immediately informed about his eligibility and if interested, he can purchase the subsidized plan.For those who do not have access to the internet, it is the responsibility of the health Exchange to provide information to these residents through other means. Hence, those residents who previously could not purchase health policies due to lack of awareness and information, the health Exchange will prove to be a one-stop shop where they can access information, compare plans and finally purchase that suits their medical and financial needs.
    Watch Sherlock Holmes 2 Online - Watch Alvin and the Chipmunks 3 Online - Watch Mission Impossible 4 Online - Watch Sherlock Holmes 2 Online Free - Watch Alvin and the Chipmunks 3 Online Free - Watch Mission Impossible 4 Online Free - Watch Glee Season 3 Episode 9 Online Free - Watch Glee s03e09 Online - Watch Glee Season 3 Episode 9 Online Free - Watch Last Man Standing Season 1 Episode 11 Online - Watch Last Man Standing s01e11 Online - Watch Last Man Standing s01e11 Online - Watch Sherlock Holmes 2 Online Megavideo - Watch Alvin and the Chipmunks 3 Online Megavideo - Watch Mission Impossible 4 Online Megavideo - Watch Glee Season 3 Episode 9 Online Megavideo - Watch Last Man Standing Season 1 Episode 11 Online Megavideo - Watch Glee Season 3 Episode 9 Online Free - Watch Last Man Standing Season 1 Episode 11 Online Free - Watch Sherlock Holmes 2 Online Free - Watch Alvin and the Chipmunks 3 Online Free - Watch Mission Impossible 4 Online Free

    Hey Andy,
    There is just as large a collection of plugins for Logic (these come in the AU or Audio Units format) as for Cubase. Anywhere you can buy recording equipment should be selling plugins too. Some free plugins (but not very useful most of the time) can be found on places like www.digitalfishphones.com or www.airwindows.com . The guy that owns AirWindows seems to basically do code copies of plugins. He's got some great free plugins. . . one of which I often use on vocals. he also has some paid plugins that are far cheaper than the competition ($60 vs. $500 for a tape emulation plugin for instance) that are VERY good.
    If you're looking to buy plugins, go to www.sweetwater.com . . . or really any large pro audio retailer, but sweetwater's a good place to start. If I knew more of what you were looking for I could help guide you a bit better.
    Also, if you have an ilok key you can download demos of many paid plugins and give them a test drive.

  • Where is the best place to put programs to start on X/Openbox startup?

    Hi,
    There are several places to put programs to startup when you start X or a WM.  I'm using Openbox and presently have placed these into my .xinitrc file, but I'm not sure this really the best place.  Openbox has a autostart file, which sorta looks like a better bet.
    Any suggestions would be great.
    Thanks,
    Jon

    Hadn't heard of consolekit; it's not clear to me from looking at their website what it's supposed to be offering? Maybe after it matures more, the documentation will improve, and all will become clear.
    When I used Openbox, I just launched everything such as conky from the Openbox autostart file. I guess if you had a weird set up such as some of your Openbox configs sitting on unmounted partitions, their mount commands would go in .xinitrc, otherwise autostart.sh seems better.
    Just IMO of course, do what you want on your own machine :-)
    Last edited by /dev/zero (2011-10-27 21:04:37)

  • Brand new macbookpro; recent install Yosemite; computer now opens to my name and image but no place to put the password but nothing happens when trying to click on restart etc.

    Macbook Pro purchased December 2014.....was fine until update iOS  to Yosemite 2 days ago. Now, when turned on my image with my name comes up on the screen...no place to put your password.....at the bottom...restart, but used cursor to click on the restart and also my name, the image etc....nothing happens.
    I shutdown to go into the Recovery OS....and got the screen about resetting the password....which doesn't need reset. The third choice seemed more appropriate regarding the keyboard...but could not click on any of them with the cursor.
    Spent an hour with Apple support who ended up referring me to an Apple store that's a 100 mile round trip from me. Can't believe they can't help me...and can't believe this is happening to a brand new Mac.....guess Apple is no different than any other computer...install an update or upgrade...and immediately have problems.
    Exasperated,
    Joe......good thing my Dell is working

    Resetting User Password in Lion and Mountain Lion
    Boot into your Recovery Partition by holding down the Command and R keys whilst booting.
    When the Recovery screen appears, go to the Utilities menu and open Terminal.
    In Terminal, type:
    resetpassword
    ...a small app will open and allow you to choose the user for whom you want to change the password. If you are the admin, be certain that you choose your admin user. Type in your new password twice and give yourself a good hint. Click OK (or Done or whatever) and reboot, enjoying the use of your new, hopefully memorable, password.
    Good luck,
    Clinton

  • How to send the Event Listener arguments in AS3?

    In MXML
    <mx:Button click="clickHandler();"
    mouseDown="downHandler(event);" mouseOver="overHandler(btn);"
    mouseMove="moveHandler('RAJAN');"/>
    but AS3
    var btn:Button = new Button();
    btn.addEventListener(MouseEvent.CLICK, clickHandler, flase,
    0, true);
    only this kind of AS3 event only added, any other possibility
    to pass the arguments to handler function.
    please help.

    From that link:
    If you define an event listener inline (inside the MXML tag),
    you can add any number of parameters as long as the listener
    function's signature agrees with that number of parameters.
    If you add a listener with the addEventListener() method (in
    ActionScript), you cannot pass any additional parameters to the
    listener function, and that listener function can declare only a
    single argument, the Event object (or one of its subclasses).
    To pass additional parameters to listener functions defined
    in AS, you must define the parameters in the listener function and
    then call some other method passing it the additional parameters in
    the call from the listener.
    You can also define your own custom events, and then you are
    free to define what args your event listeners take, and access the
    data from the event object.

  • Where is the best place to buy the new ipad? Please help

    I am ready to buy a new ipad.  There is no apple store in my town but I will be close to one in a couple of days.  My town has Best Buy, Target, and Walmart.  Assuming I can find what I want... in case I have issues with it, where is the best place to purchase from??  (as far as ease of return, etc). Please advise.

    Dah*veed ..... I do not disagree with what you said about the AppleCare+ protection plan as it does state on the website that proof of purchase is required - IF ... You purchase over the phone. Actually, I did not expect to be able to do this over the phone, but as I said I received the paperwork today via email.
    I copied this from the website and I'm typing this on my new iPad so it may come out a little distorted but you can read the sentence at the bottom that says it can be done over the phone with proof of purchase. I gave the rep my serial number, confirmed my address and CC details and the deal was done. I even called back later in the day to make absolutely certain that I did in fact purchase the AppleCare+ plan that has the two incidents of accidental damage included for a $49.00 charge. The rep did in fact confirm that I did buy the correct plan that I wanted and I am looking at the printed paperwork confirming the whole thing.
    Maybe I just got lucky!
    iPad - AppleCare+
    Every iPad comes with one year of hardware repair coverage and 90 days of telephone technical support. AppleCare+ for iPad gives you two years of repair coverage and technical support from the original purchase date of your iPad. And it adds coverage for up to two incidents of accidental damage due to handling of your iPad, each subject to a $49 service fee.1
    How to get AppleCare+
    You must buy AppleCare+ within 30 days of your iPad purchase.
    There are three ways to buy:
    From the Apple Online Store: When you order the new iPad or iPad 2, you’ll have the option to add AppleCare+ to your cart before you check out.
    At an Apple Retail Store (requires a Genius Bar appointment, inspection of the iPad, and proof of purchase).
    By calling 1-800-275-2273 (requires proof of purchase).
    Learn more

  • Best place to put validation code?

    Hey,
    When using jsp and html forms for passing information from the
    client to the server, where should i put the validation code? Is
    it better to put the code in the bjc4 classes or to make some
    FormHandler.jsp which checks wheter correct values/types typed
    in the form by the user?
    If i put the code in the bc4j classes, how can i then interact
    with user, when he makes an error?
    thx

    The question is the classic stand off between resuablity and
    modularity and user interface.
    If you put the validation code in the client (jsp) then the user
    sees the error quickly and it is relatively painless. However,
    if the rules change, you must change ALL of the clients that
    enforce that rule.
    If you put it in the middle-tier then there is the delay in the
    user feedback. The middle-tier will only validate the code on
    some sort of post. However, your validation code will be in only
    one place and therefore easy to maintain over time.
    So what's the solution. I suggest for JSPs a combination. If the
    rule is a real business rule then it needs to be validated in
    the middle-tier. If it is something that is prone to user typing
    error and is simple enough to be enforced within html, then it
    should go there also. You must remember that those client based
    rules can spread and your maintenance effort will go up.
    Gary
    JDev Team

Maybe you are looking for