Simple questions on the earphones of events and memory management

I am brand new to AS 3.0 (have not coded in 10 years!) and I have a two part question on the management of event listeners.

1. is it possible to use variables or loops to simplify the process of creating event listener? For example, I have a scene that animates the leaves when they are hit. There are 25 or more leaves, so I need to handlers of 25 and 25 functions, even if the animation is the same. Right now my code looks like this:

leaf1.addEventListener (TouchEvent.TOUCH_BEGIN, animateLeaf1);
leaf2.addEventListener (TouchEvent.TOUCH_BEGIN, animateLeaf2);
leaf3.addEventListener (TouchEvent.TOUCH_BEGIN, animateLeaf3);

etc. And then the functions all alike as well.

function animateLeaf1(e:TouchEvent): void {}
leaf1.gotoAndPlay ("animationStart");
}

function animateLeaf2(e:TouchEvent): void {}
leaf2.gotoAndPlay ("animationStart");
}

etc. My instinct tells me there is an easier way to do this, but I don't know if it's just because I see a model and want to put it in a loop or if there is really a better way to do it. I have event listeners are doing right?

2. How can I clean my waste? Each of my frames will have 100-300 earphones of events inside, for animations, etc., mainly because a single button can have 3-5 event listeners (touch Start, end touch, touch roll on, roll off touch, etc.). Is this too much for a mobile device to manage? When can I disable event listeners to make sure that they are the garbage collector to release the memory? I don't want memory leaks, but the event listeners must be active when the frame is active and destroyed when the setting is inactive; I don't know how to program which, or if such a garbage collection is already inherent in Flash.


Thank you very much!
Amber

leaf1.addEventListener (TouchEvent.TOUCH_BEGIN, animateLeaf);

leaf2.addEventListener (TouchEvent.TOUCH_BEGIN, animateLeaf);

leaf3.addEventListener (TouchEvent.TOUCH_BEGIN, animateLeaf);

leaf4.addEventListener (TouchEvent.TOUCH_BEGIN, animateLeaf);

function animateLeaf(e:TouchEvent): void {}
e.currentTarget.gotoAndPlay ("animationStart");
}

Tags: Adobe Animate

Similar Questions

  • Question of the order of events and functions

    Hello

    Sorry for the stupid question, but I'm working on something big and I would hate a small rock to thow me off in the end.

    So here it is:

    I not know how to operate the functions-> if you have:

    function function1() {}

    function3();

    }

    function function2() {}

    }

    function function3() {}

    }

    function1();

    function2();

    First runs function1 and function2 and function3. Is simple baptisms the function1 + everything it has nested functions again from the top to the bottom, then function2 etc.

    OK, so now I have this situation:

    If you have an INTERNAL component that is in the MAIN component. If you addEventListener (FlexEvent.CREATION_COMPLETE, test) inside of the INSIDE (class of the function of construction in my case) and also add the same event listener once again inside but the MAIN ingredient such as:

    public void main_creationCompleteHandler(event:FlexEvent):void {}

    inner.addEventListener (FlexEvent.CREATION_COMPLETE, test);

    addElement (inner);

    }

    Then you will have 2 event for the same event listeners. First one written to the INNER component will run, and then it will run in the MAIN component.

    Now if I set many many functions in INNER creationCompleteHandler, will all 100% complete before the creationCompleteHandler to HAND work?

    As I tested it, it looks like each treatment must be 100% made to the INNER creationCompleteHandler before it passes to the creationCompleteHandler of HAND.

    Can someone confirm that flash/flex works like that? Thank you!

    FM_Flame wrote:

    Hi Alex, guys,.

    so, I would like to summarize the question and if we can just say Yes or I guided even what is Yes, then there is no confusion

    Here are 2 scenarios:

    1) 2 headphones are added to the same same thing e.g. CREATION_COMPLETE - one for the component and the other to the container.

    It works like this:

    un) pane-> creationCompleteHandler starts to perform its functions/activities

    b) containing-> creationCompleteHandler starts to perform its functions/activities

    The question here is: will a) be 100% full before before flash moves to b) or b) could happen sometimes some time one) is running?

    Note: Yes this means a) will be 100% complete bofore b) occurs.

    2) for the second scenario allows to take 2 different events INITIALIZE and the FlexEvent CREATION_COMPLETE and add the listener both in the component only this time, so we do not complicate things.

    It works like this:

    un) pane-> initializeHandler starts to perform its functions/activities

    b) pane-> creationCompleteHandler starts to perform its functions/activities

    The question here is the same: will a) be 100% full before before flash moves to b) or b) could happen sometimes some time one) is running?

    Note: Yes this means a) will be 100% complete bofore b) occurs.

    Thank you very much

    (1) flash is currently single-threaded, so a Manager will end before the end of another Manager for the event itself. The processing order is not guaranteed and since your handlers are listening for the event attached to the same object, that it is imprudent to write code that depends on the order in which these handlers are called. Adobe are working to multi-threading the flash plugin, in the future any order that may now exist differrent in the future and any treatment that depends on a single completion handler until the other is called can also fail in the future because a multi-threaded player could activate the two managers simultaneously.

    It's nice to have answers Yes/No, but only if you want to write poor code that can work, by accident, until something changes that you have no control over.

    Do not write code that depends on the order this event handler is called for the same event.

    (2) initialize occurs before the complete creation. The answer is Yes.

  • question about the scope of variables and memory

    I searched the Adobe documentation for an overview, but apparently, I'm not in the right place.

    Here is an example of simplified code:

    < AS >

    loadedImages:Array = new Array();

    function createImageData(imageNumber:Number):void
    {
    var imageData:BitmapData = new BitmapData (width, height);

    Switch (imageNumber)
    {
    case 1:
    imageData.draw (loader1.content);
    loadedImages [imageNumber] = imageData;
    break;

    case 2:
    imageData.draw (loader2.content);
    loadedImages [imageNumber] = imageData;
    break;
    }
    }

    < virtue >

    ImageData defined inside the function createImageData(), I know that I can not access any outside level of the function block.  But what about memory?  ImageData still exist once the code has "left" the createImageData() function?

    For example, if the function above is called twice (once with imageNumber = 1, once with imageNumber = 2), what I remember?

    -BitmapData objects stored in loadedImages [1] and loadedImages [2] and 1 BitmapData object named imageData

    -BitmapData objects stored in loadedImages [1] and loadedImages [2] and 2 BitmapData named imageData objects

    -BitmapData objects stored in loadedImages [1] and loadedImages [2] and nothing else

    Is there a way to see the 'elements' in memory, not just the quantity?

    If you call twice createImageData, for imageNumber = 1 and imageNumber = 2, there will be only 2 persistent objects to the Bitmap in memory, and they will be made by the loadedImages table. The imageData variable is just the first to receive the pointer to the allocated memory and past him on the elements of the array until it's life is over. Only when you delete the table, you will release the objects for the GC.

  • I have a simple question about the meta-data.

    Hello. It is a simple question about the meta-data. How can I get the video bitrate of a flv or mp4 (video playing via NetStream file) file

    right now I have this:

    Code
    var netClient:Object = new Object();
    netClient.onMetaData = function(meta:Object)
    {
    for (var in meta props) {}
    trace (props + ":" + meta [props]);
    }
    MovieClip (root) .durations = meta.duration;
    trace (MovieClip (root) .durations);
    };
    NS.client = netClient;

    And my output is:

    videocodecid: avc1
    audiocodecid: m4as
    aacaot: 2
    Width: 960
    AudioChannels: 2
    videoframerate: 23.976
    TrackInfo: [object Object], [object Object]
    moovposition: 32
    avcprofile: 77
    audiosamplerate: 48000
    avclevel: 31
    seekpoints: [object Object], [object Object], [object Object], [object Object]
    height: 540
    Duration: 221.312

    As you can see, there is nothing of video bitrate.

    I know that the video bitrate of my videos, but then I have to manually type each number of bitrate into my flash project, and it would be such a fuss when I have a lot of videos. Would be nice if flash can detect the video bitrate.

    It's for my online portfolio.

    Why you divide by 8?  If you want to convert bytes into bits, multiply by 8.

  • How to detect the window closing event and to do some tasks before leaving

    Hello

    Someone knows how to detect the window closing event and to do some tasks before leaving?

    Sridhar

    Structure of the event allows to detect the window closing event. In the structure of the event,.

    Select this VI-> close round table for this task. See attached picture.

  • simple question: is the f2280 a printer/scanner wireless?

    Simple question: is the f2280 a printer/scanner wireless?

    This widget could not be displayed.
  • Simple question on the passage of ID variables in a url after you add a new record

    Hello;
    I know it's a simple question, I have a brain block. I'm going from a form and insert a new record in the db, but after I insert the new record, I want to pass the ID variable that gets are entrusted to him. How can I do this?

    It's my code to insert:

    < cfset EventDate = "#DateFormat(form.eventDate,"mm/dd/yyyy") #" >
    < datasource = "" #APPLICATION.dataSource # cfquery "dbtype ="ODBC">"
    INSERT INTO events
    (title, eventDate, eventTime, location, contact, telephone, fax, email, URL, sponsor, body)
    VALUES (< cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.title #" >,)
    < cfqueryparam cfsqltype = 'cf_sql_date' value = "" #EventDate # ">,"
    < cfqueryparam cfsqltype = "cf_sql_time" value = "#form.eventTime #" >.
    < cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.location #" >.
    < cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.contact #" >.
    < cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.phone #" >.
    < cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.fax #" >.
    < cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.email #" >.
    < cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form. "URL #" >.
    < cfqueryparam cfsqltype = "cf_sql_varchar" value = "#form.sponsor #" >.
    < cfqueryparam cfsqltype = "cf_sql_longvarchar" value = "#form.body #">) "
    < / cfquery >
    < cflocation url = "events_RecordView.cfm" >

    In the cflocation I want to pass the variable ID, how about a new record?

    Thank you.

    CFmonger

    Try this. This will select in the query exactly what was inserted just enter the id and pass id just to get in the variable. If two people fill out the form at the same exact time, that assure that they are redirected to the appropriate page.

  • A few questions about the use of data and Cliq

    I have the cliq, however I chose to not get 3G (so I bought full fare). So I have a few questions about the phone and the use of 3G / 2 G/Edge:

    1 - is possible to disable completely the 2G / 3 G/Edge? I know you can switch between them, but are anyway just tell the phone to stop using them altogether since I'm not subbed to the service?

    2. when the update takes place, I guess we'll have to reconnect motoblur and etc, but if I don't have 3 G will I have motoblur connection problems after the update? Or he keeps the latest wifi settings so that it would connect to wifi to connect. When I first got my phone it was not a problem b/c I had 3G for the first month.

    I hope that makes sense, thanks!

    To stop all the data, I would like to download an application called APNDroid. He cut them all down. When you log on to blur you have 3G or WIFI doe this without getting a timeout error. During the process of setting up your Blur account, you can press the menu button and set up your wifi to work, this will connect you to Blur and your phone will be connected to the blur. If I were you I would be rethinking to do a data plan since you are really losing out on most of your main features of phones. It's your choice, however.

  • Legal question on the use of PwDump and utilities inject NT hashes in an ad

    Hello, I want to be able to inject actually stored in an OpenLDAP in a Drectory Active NT hashes.
    However, I have not found any solution without knowing the user to clear the password (which is not an acceptable solution for me).

    I intend to use the sources of PwDump6 and his ability to inject code through 'lsass.exe' to be able to import NT hashes in Active Directory using the method "SamrSetInformationUser".
    My question is not on the virtue of technique, but the legality of this.

    If I managed to do, - is it legal to use Microsoft point of view? And distribute the source publicly?

    It is a forum for peer to peer, not Microsoft. You will need to contact them directly. Look for the coordinates on the microsoft.com site

  • Simple question about the signing of the app

    Hello.

    I develop libraries to be used in other apps.

    It will be a cod file, its name will be added to the jad as a dependency.

    My library has access to the secure API (call of the browser), so I have a simple question:

    can I register only my cod library or application that uses my library is expected to be signed in too?

    THX.

    You should be ok just signature cod of the library, if your application uses any API secure. However, I just make a habit to sign everything just in case.

  • Fresh paint - Questions on the mixture of colors and model packs

    Hi all

    I have 2 questions for fresh paint where I can not find an answer for.

    1. own models

    Fresh paint offers to buy packs of model that can be used for painting. I have a few models that I would use it as well. I know, it is possible to open an image and paint it, but there is a big difference. Models that are offered by the application itself have a big advantage - with a special button (showing a few mountains & Sun) to within the application, you can enable / disable the view to the model (which in fact becomes visible or hidden) as a kind of layer, so you can easily check your paint with and without the model. Is it possible to do both for own patterns / Images? When I used my own jpeg file 'mountains' button is not available.

    2 using the palette color mixing and putting them in one of the holes tiny 'color selector' on this issue - how is this possible and how can such color to delete as well?

    I would really like to know how the colors can be mixed / saved / deleted using (the Palette on). Sometimes, when I mixed 2 colors and used in my painting, the color is not yet available in the Palette itself for easy reuse, sometimes it will fill one of the spots on it, however for me ist currently unclear in this case - which makes it unpredictable. Will there be some indications on how to use the color scheme and its functions?

    Thank you very much

    André

    Hi all

    I have 2 questions for fresh paint where I can not find an answer for.

    1. own models

    Fresh paint offers to buy packs of model that can be used for painting. I have a few models that I would use it as well. I know, it is possible to open an image and paint it, but there is a big difference. Models that are offered by the application itself have a big advantage - with a special button (showing a few mountains & Sun) to within the application, you can enable / disable the view to the model (which in fact becomes visible or hidden) as a kind of layer, so you can easily check your paint with and without the model. Is it possible to do both for own patterns / Images? When I used my own jpeg file 'mountains' button is not available.

    2 using the palette color mixing and putting them in one of the holes tiny 'color selector' on this issue - how is this possible and how can such color to delete as well?

    I would really like to know how the colors can be mixed / saved / deleted using (the Palette on). Sometimes, when I mixed 2 colors and used in my painting, the color is not yet available in the Palette itself for easy reuse, sometimes it will fill one of the spots on it, however for me ist currently unclear in this case - which makes it unpredictable. Will there be some indications on how to use the color scheme and its functions?

    Thank you very much

    André

    Hello Andrew,.

    At this time, "Own Templates" are not supported.  This is a feature that is only supported for activity Packs that are published.

    Mixing of colors, custom colors mix you are only saved if you use somewhere in your paint.  Then, they are automatically saved in your palette.  Your custom palette is only applicable to an individual work you created with it.  There is no need to remove the colors we provide a long list, you can scroll through directly under the area of mixture.

    You can reposition your palette customized by drag-and - drop colors between the lodges on the palette.  This allows to reposition some colors in your well static tasks.  Well custom tasks will be to repopulate it based on the most frequently used colors.

  • simple question for the first time the user: someone please be a hero

    Forgive the restorative nature of this question but the FM help files are surprisingly usless for the first time and users.

    I did successfully a rectangle graphic.  Now, I want to put some text in the rectangle.  I see that I can't just click on and type.  Apparently I have to, I don't know, do a "framework" of text or something?  I don't see why this is so complicated or why the help docs do not begin at the obvious base.

    Please throw me a bone and wander if this.  I use 9 FM, but I am sure that the version is not serious.

    Thank you!

    There are two possibilities to place text on a chart.

    One is to use the "text tool" in which you can type a string of text whenever you click on the slider.  You can format the string, but you cannot apply a character tag or a paragraph tag. And you can't put a carriage return make several lines; to do this, you need to add the additional lines of text.

    The line of text tool is the letter 'A' that appears in the icons when you consider > toolbars > toolbar graphics.

    Second method is to create a text frame, and then type in it. You can apply paragraph tags, tags of characters, use of CRs and so on in a text frame.

    Text frame tool is the small square with several lines in, just above the "A" icon in the Graphics toolbar.

  • Question about the guest of dashboard and column

    My question about the dashboard and column prompt:


    (1) prompt dashboard usually work with only for columns that are in the topic area. In my report, I have created some of the columns that are based on other columns. As I have the daysNumber column that is based on two other columns, because it calculates the difference between two dates. I can't find this column invites when I create dashboard. I need to make a guest on this column.

    (2) to one of the column, I have only two values 1 and 0. When I create a prompt for this column, is possible that falling of drop down it displays 'Yes' of 1 0 and 'No' and always filter the request?

    Hello...

    I forgot to tell you one thing... but performance wise... If you create the column in RPD itself, it is good and easy to maintain.
    If you want this feature also... once again you choose directly the column in the area of topic... ;)

    Thank you & best regards
    Kishore Guggilla

  • Equium P200-1ED - Question on the possible 2nd HD and RAM

    Hello

    I've got the Equium P200-1ED and in the manual (page with diagrams showing the characteristics of the laptop), it mentions a second hard drive.
    I know my P200 does not have a second mounted drive so does that say space to eventually mount a second drive?

    Also, is it true that the max supported ram is 2 GB?
    It would be nice to upgrade the standard 2 GB Ram.

    Thank you

    Hello

    Well, the second HDD depends on the single model.
    The second HARD drive Bay must be placed close to the first HARD drive Bay.
    You can remove the cover that secures the second HDD and can check if the necessary controller is available on your laptop.
    Please note that the second HARD drive Bay could be available but without the HARD necessary interface disc.

    Regarding the upgrade of memory;
    If your laptop was equipped with Intel 945 GM/PM Express chipset or higher, you can update the memory up to 4GB. If the laptop was equipped with an Intel 943GML Express chipset, you can upgrade the memory up to 2 GB.

    But note; 32-bit Windows system will recognize only 3GB due to the 32-bit Microsoft Windows operating system limitation.

    Best regards

  • Questions about the standard wireless keyboard and mouse on a h8 - 1360 t.

    Hi again,

    I have a h8 - 1360t with the standard wireless keyboard and mouse.

    1. where is information on the blue buttons 'connect' keyboard and mouse?

    2. the mouse has a power switch - do I really have to close each time, or is there a function of inactivity when the system is off?

    3 lets say that I have two exact systems within 5 feet of each other. Will the two keyboards and mouse conflict?

    Looking forward to your answers.

    Thank you

    BJ

    This document will show you how to sync mouse wireless and keyboard if they connect buttons.

    You don't need to turn off the wireless mouse. If you have problems with the batteries run out frequently, it might be useful, but I've never needed to do.

    Two different sets of wireless mice/keyboards are not usually a problem. If there is a conflict, go through the process of connection of each game.

Maybe you are looking for