creation of function in a loop

Hello-

My problem is that I have created a bunch of buttons dynamically in a loop and to include a "onRollOver", different for each button function. However, variables that I put in the functions are all being replaced by the value of the last pass through the loop. How can I generate another body of the function for each button that I'm generation?

my code:

var dataIndex = 0;
[while loop]
{
var name = "instbut_" + dataindex;
var button = container.createEmptyMovieClip (Anom, 100 + dataindex);
[...]
container [name] .onRollOver = function() {trace ("my button name is" + name) ;}
dataIndex ++;
}

When it works, it generates correctly four buttons - but when I roll over each, 'Anom' is always equal to "instbut_3". How can I force it to generate four separate functions, instead of a single referenced by all the buttons together?

Thanks for the tips!

-miranda

var dataIndex = 0;
[while loop]
{
var name = "instbut_" + dataindex;
var button = container.createEmptyMovieClip (Anom, 100 + dataindex);
button.myName = name;
[...]
container [name] .onRollOver = function() {trace ("I name the button" + this.myName) ;}}
dataIndex ++;
}

By the way, you could use this instead, but for other variables ._name, give the value you need before writing the handler and then target values with this.

Tags: Adobe Animate

Similar Questions

  • Requried helps the creation of function

    Hi all

    I need assistance to create feature my input parameters for this function will be 1 or 1,2 1,2,3

    my output should be

    If I pass 1 as an input parameter, it should return 1
    If I spend 1, 2 as input parameter it should return 1.2 in different lines
    Even if I switch 1,2,3 as an input parameter it should return 1,2,3 in different lines.

    Can someone help me please in the creation of this function.

    Thanks in advance.

    Published by: p78 on January 16, 2012 03:31

    Published by: p78 on January 16, 2012 03:31

    Hello

    It will be something like that. You must first type to return lines (use another number, for example data type if you must):

    CREATE OR REPLACE TYPE t_list AS TABLE OF VARCHAR2 (4000);
    /
    

    Then, the function will be a pipeline function:

    CREATE OR REPLACE FUNCTION in_list (p_list  IN  VARCHAR2)
      RETURN t_list PIPELINED
    AS
      l_text  VARCHAR2(32767) := p_list || ',';
      l_idx   NUMBER;
    BEGIN
      LOOP
        l_idx := INSTR(l_text, ',');
        EXIT WHEN NVL(l_idx, 0) = 0;
        PIPE ROW (TRIM(SUBSTR(l_text, 1, l_idx - 1)));
        l_text := SUBSTR(l_text, l_idx + 1);
      END LOOP;
    
      RETURN;
    END;
    /
    

    now, you can query (or whatever the needs):

    select * from table(in_list('aa','bb'));
    

    Herald tiomela
    http://htendam.WordPress.com

  • An array of strings as function parameter in loop fails

    Hallo,

    I have a weird problem here and I hope someone can help me find the cause.

    I have a function where I said an array of strings (string_list). I pass the array to a function that does modifactions to the table. I am addressing Walker the array of strings to an index of all the values are stored correctly. When I loop through the array by incrementing the index automatically only the last index value are saved in all positions.

    Why is this? Or what I am doing wrong?

    It is the passage to another function, an array of strings
    int calling_function
    {
    char * string_list [MAX_PATHNAME_LEN]; //< store="" strings="" in="">
    function_called (string_list); passing a pointer to an array of string
    return 0;
    }

    This is the function receives a reference to an array of strings to store data
    int function_called (char * output_list [])
    {
    int i = 0; counter variable
    / * This works and good values are stored in output_list * /.
    output_list [0] = '02 ";
    output_list [1] = '12 ';
    output_list [2] = "22";
    output_list [3] = "32";
    output_list [4] = '42 ';
    output_list [5] = "52";
    output_list [6] = '622 ';
    output_list [7] = "72".

    / * This does not work and will store '31' in all places of the matrix * /.
    < 32="">
    {
    < %d »,="" i) ;="" incrémenter="" la="" valeur="">< br=""> output_list [i] = sample; < br=""> i = i ++ ; < br=""> < br="" >="">

    output_list [0] = '02 "; < br=""> output_list [1] = '12 ';< br="" >="">

    Thanks!

    Hi,.

    When you do

    output_list [i] = sample;

    all of the members of the array have the same value: sample-a char pointer. You are modifying the afterwards glad of sample purpose the previous values still point to sample.

    If you assign values to each array member like:

    you assign different values: a pointer to a string containing "02", pointing to a string contaning "12",...

    If you want to assign values in a loop you need to allocate memory for each string (output_list [i]) and copy the content of sample in them.

    Does this make sense to you?

    Constantin

  • Execution time of the XML CVI functions increase when loop

    I wrote several functions with CVI who read XML files. I confirmed in the utility of monitoring resources I have cleaned all my lists, items, documents, etc. I found that when I loop one of the functions I created, the execution time increases. The increase is small, but it is sensitive and does not affect the performance of my.

    Are there other sources of memory I need to release? It seems that there is a leak memory somewhere, but I can't see where this increase.

    I am running LabWIndows/CVI 2009 on Windows 2008 Server. I closed my functions using TestStand 4.2.1. Any help would be appreciated!

    Thanks in advance,

    Kyle

    Hi Daniel,.

    After some playing around, it turns out that the source of my problem was due to running my program as a Debug version, rather than a Release. As soon as I build in a configuration of output, the function remains coherent and quick time loop.

    Thank you for the research on this problem for me.

    Kyle

  • passing parameters to a function in a loop

    How to pass the values of a loop (for example, the increment count) to a function onRelease inside this loop for? in the example below the movie clip will go always to "whatever.php? var = 10" being the value of i when you click it, 10. I want the value of i to include for each execution of the loop. How do I do that? I'm guessing that maybe a listener, but I can't get anything to work.

    Try like this:

    var host: MovieClip = this;

    for (var i = 1; i)< 10;="" i++)="">
    var t = home.attachMovie ("myMovie", "myMovie" + I, i);
    t.myI = i;
    t.onRelease = function() {}
    getURL ("whatever.php? var =" + this.myI);
    }
    }

    --
    Dave-
    Developer leader
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.Adobe.com/communities/experts/

  • creation of Subvi in for loop problem

    Hi guys

    I am trying to create sub - VI but part entering inside the Sub - VI contain the loop. As soon as I chose the part of my program for which I want to creat Subvi it a pop up comes. I'm posting pictures of the pop up and program. In the picture of this program, I want to create a Subvi for (for the loop with 10 iteration).

    Please help me find the solution. Your help, I'll appriciate.

    A lot of your local variables must be simply replaced with wires or shift registers.  That would eliminate some of your questions.  Otherwise, I would delete just your seeing terminals before creating the Subvi.

  • help in the creation of function.

    Hi guys I am a newbie in pl/sql...
    I want to create a function that bed alll the lines of a table containing hundreds of lines...
    Break all the lines separated by space in several blocks or columns and check certain conditions on each block/columns...
    For example:
    I have a table that is to have a GBA and hundreds these lines...

    12345 1234 12345 12345 12345 12345 12345 12345
    .
    .
    .
    .
    Now, I want to create a function or a procedure that reads all the lines and check certain conditions on every word of each line...

    for example: 1st condition:
    1st, 2nd, 3rd, 4th and 5th Word is 12345 or not...
    2nd, 3rd, 4th, 5th, 6th Word is 1234 or not
    3rd word has a length = 5 or not, and various other conditions... but one thing is sure, I must check all the words in the line with respect to each condition...


    thnx in advance...

    Or...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with testdata as (select '12345 12345 12345 12345 12345 12346 12347 12348' as txt from dual union all
      2                    select '54321 1234 1234 1234 1234 1234 32785' from dual union all
      3                    select '10101 10101 10101 10101 10101 10101 10101' from dual union all
      4                    select '123 123 123 123 123 123 123' from dual)
      5  --
      6  -- end of test data, use query below
      7  --
      8  select txt
      9        ,case when wrd1 = '12345' and wrd2 = '12345' and wrd3 = '12345' and wrd4 = '12345' and wrd5 = '12345' then
     10                'True'
     11         else 'False' end as cond1
     12        ,case when wrd2 = '1234' and wrd3 = '1234' and wrd4 = '1234' and wrd5 = '1234' and wrd6 = '1234' then
     13                'True'
     14         else 'False' end as cond2
     15        ,case when length(wrd3) = 5 then
     16                'True'
     17         else 'False' end as cond3
     18  from (
     19        select txt
     20              ,regexp_substr(txt,'[^ ]+',1,1) as wrd1
     21              ,regexp_substr(txt,'[^ ]+',1,2) as wrd2
     22              ,regexp_substr(txt,'[^ ]+',1,3) as wrd3
     23              ,regexp_substr(txt,'[^ ]+',1,4) as wrd4
     24              ,regexp_substr(txt,'[^ ]+',1,5) as wrd5
     25              ,regexp_substr(txt,'[^ ]+',1,6) as wrd6
     26        from testdata
     27*      )
    SQL> /
    
    TXT                                             COND1 COND2 COND3
    ----------------------------------------------- ----- ----- -----
    12345 12345 12345 12345 12345 12346 12347 12348 True  False True
    54321 1234 1234 1234 1234 1234 32785            False True  False
    10101 10101 10101 10101 10101 10101 10101       False False True
    123 123 123 123 123 123 123                     False False False
    
  • Creation of function to calculate average

    Hello

    The following query has been successfully returned an average value. He returns 1 row.

    ---
    SELECT AVG (Volume)
    SECURITY
    WHERE
    Type = 'Future' AND
    Note = "AAA" AND
    Code = 1 AND
    (Day = "14-mar-09' OR)
    Day = 16-mar-09' OR
    Day = ");
    ---

    I tried to use this function on my function created below.

    --------
    FUNCTION to CREATE or REPLACE fn_Vol_Average

    (DATE IN v_DayLast_1_Week,
    v_DayLast_2_Week IN DATE,
    v_DayLast_3_Week IN DATE)

    RETURN NUMBER IS
    v_Vol_Average NUMBER;

    BEGIN

    SELECT AVG (Volume) IN the v_Vol_Average
    SECURITY
    WHERE
    Type = 'Future' AND
    Note = "AAA" AND
    Code = 1 AND
    (Day = v_DayLast_1_Week OR)
    Day = v_DayLast_2_Week OR
    Day = v_DayLast_3_Week;)

    RETURN NVL (v_Vol_Average, NULL);

    END;
    ---------

    I called this function with the following query. It was work, but it return the whole lines. It seems the function to perform the calculation of the average of each lines on the table.

    Can someone help me what happens with logic?
    --
    Select fn_Vol_average('14-mar-09','16-mar-09','')
    Security
    --
    select fn_Vol_average('14-mar-09','16-mar-09','')
    from security
    

    What you trying to accomplish?

    Maybe you wanted to say:
    Select fn_Vol_average('14-mar-09','16-mar-09','')
    from DUAL;

    It's kind of a weird way to write and call a function well.

  • Can you create multiple variables with a function or a loop?

    I want to dynamically create variables that will create and place instances of a clip on the stage during execution. Is this possible? Here's what I came up with, I know it's super bad. Any help is very appreciated:

    var counter: number = 3;

    for (var i: int = 0; i < Count; i ++)

    {

    var a: number = i

    var a: pill1_mc = new pill1_mc();

         i.x = 600;

         i.y = 55;

         if (i != 0)

         {

    i.y = (i-1) there + 36;

         }

    }

    Actually no, it creates a new instance on each iteration. Try it for yourself and see - addChild (a) just at each iteration. Another question, is perhaps, if you want to keep the reference to each instance and treat it somehow in the future. In this case, one of the ways is to store instances in a table and then refer to them as needed - you're on the right track:

    var counter:int = 3;
    var a:pill1_mc;
    var nextY:Number = 0;
    var movies:Array = [];
    for (var i:int = 0; i < counter; i++)
    {
         a = new pill1_mc();
         movies.push(a);
         a.x = 600;
         a.y = nextY;
         addChild(a);
         nextY += 36;
    }
    
  • asynchronuous functions do not work in a c# used by CVI application dll

    Hello

    I have an application written with CVI 9.0.1, who must interact with a dll c# 2010 (which has no window) through a CVI<->wrapper .net (created with the controller of the CVI useful .net).

    This c# dll uses the functions asynchronuous, as NetworkStream.BeginRead () and EndRead() of an object of System.Net.Sockets.TcpClient for example.

    These asynchronuous functions work very well when the c# dll is used by a c# application (with a main window) or the c# dll is converted into a stand-alone c# program (having a window with buttons, call its methods, just to try), but asynchronuous functions do not work when my c# dll is called by my CVI application (which is my goal) : execution remains inside the NetworkStream.BeginRead () for example (for the concerned thread).

    NetworkStream.BeginRead () can be bypassed successfully by using the function alternator NetworkStream.Read () instead, but the c# dll uses any other asynchronuous functions which have no associated alternator function.

    Here's some c# code (I don't have the source code of the Snmp object; got_trap() method is never called when asynchonuous calls do not work):

    public void run() / / wire

    {

    SNMP snmp = null;

    Try

    {

    SNMP = new Snmp (true);

    SNMP. NotifyListenPort = 162;

    SNMP. NotifyRegister (null, null, new NotifyCallback (got_trap), CB_DATA_);

    isActive = true;

    Timeout.Infinite;

    }

    ...

    }

    Thinking it might be a problem with the window messages that could not be processed (in the c# dll), I tried to replace the Timeout.Infinite statement in the code where the management of asynchronuous are held, by a creation of window over my loop of messages in Win32 window, but asynchronuous functions do not work better (while my loop seems to process messages successfully) :

    Form myForm = new Form(); an empty window

    myForm.Show ();

    int bRet;

    MSG msg = new MSG();

    While ((bRet = GetMessage (out msg, IntPtr.Zero, 0, 0))! = 0)

    {

    If (bRet == - 1).

    {

    handle the error and possibly out

    }

    on the other

    {

    Switch (msg.message)

    {

    default: / / everything else

    TranslateMessage (Ref msg);

    DispatchMessage (Ref msg);

    break;

    }

    }

    }

    Any idea?

    Thank you

    rvfr.

    Solved: in fact, the Assembly of snmp I used just need to be registered dotNet.

    rvfr.

  • Output of MatlabScript in the matter of the loop

    Hello everyone, but long time reader first time poster, and I was wondering if I could get help to a little problem here, or... Well, more like a question and not a problem.

    I don't download the .vi because I don't think it will be necessary, in addition, ignore the rest of the image (I just play with image processing like I taught him) and go to the location of the matlab script.

    My goal is to represent the image (taken from image data) bit and in the end, it must look like to... a table of 8 columns and all the lines she might need (can't see all of the lines of course) so it will look like a matrix.

    For example, it should look a bit like this on the user Panel
    | 1. 0 | 1. 1. 0 | 1. 0 | 1. (first 8 bit value)

    | 1. 0 | 1. 1. 1. 0 | 1. 0 | (8-bit second value)

    etc...

    So for that, I use the matlab de2bi function and the release of this part is where my problem is, im putting out 8 columns representing each number comes from the image and well, im confused as to what is going out of the matlab function and the loop, as you can see in the picture I have uploaded, I put a flag in the output of 'bin '. , was automatically called Real, inside the loop and the other digital, outdoors, also, I disabled the index of the tunnel in this output. (if I activate the index, it comes out as a table)

    I thought that Real and Numeric to be showing the same thing, but when I run it, which doesn't seem to be the case, you Real shows the 1 and 0 (I guess it shows the 8 bits because it shows figures but I saw in the matlab command window and there are 8 bits stored in 'bin') and digital remains just at 0 its almost as if nothing were happening out of the loop, and because I'm not sure what it is falling I can't really find a way to show the bits as in the example, I said before.

    Read the help of de2bi, it is said that his exit is a matrix if the input is a vector, but I don't think it's a vector since due to the loop, it takes value by value, then it must go to the default (in binary) value too...

    Thanks for the help in advance, in addition, whether something else to better understand my problem please say so and I will do my best to make it easier to understand.

    I don't know why you're so obsessed on matlab, LabVIEW can do all this much simpler directly. Here's a possible solution. (LabVIEW 8.5. For other possible outputs you could reverse the Boolean array, so modify them.).

    (Your main mistake under matlab is that your output of matlab is defined as a scalar value, then it should be a vector. Your tunnel to exit of the matlab node has the wrong data type.)

  • Looking for a Boolean function similar to or, but do not wait for the second entry in case he gets a 'real' a single entry

    my program works in 2 processes in parallel inside a while loop and should stop when one of them ends.

    How can I do? Uses the function 'Or' wire loop the stop condition will not do the job, waiting for the two processes to give their comments before running.

    What I really need is a function that waits until she gets a 'true' through one of its entry and then executes without waiting than the other.

    Y at - it such an option?

    If not, does anyone have an idea how to achieve what I have described here?

    Thanks in advance!

    What you need is a "not synchronous or", i.e. "do something if Item 1 becomes real GOLD point 2 becomes true.  One way that comes to mind to do is with a design of producer/consumer model (event), where the consumer is a State Machine with a shutdown state.  Get 1 point to trigger an event (perhaps using a user event or property Value Change (follow the signs)) when it turns out true, and have it send to the consumer the Stop State.  Download point 2, to do the same thing.  Now one of them becoming true will cause the shutdown state be registered (without taking care of doing the other element), in other words, that becomes a real, (consumer) loop stops.

    Bob Schor

  • AVI function Write 2 'freezes' computer

    I am trying to run four cameras through the PCIe-8244 USB3.0 card and collect videos of each of them separately. This is proving to be an extremely difficult task. (LabVIEW 2013)

    So far, I have IMAQdx works very well for both cameras to display on the front panel. However as soon as I try to register, I can't rely on all other controls on the front panel, which has begun registering other impossible cameras, here is a picture of what is running. I tried to put the avi Write 2 function in call loops or just with timers and in both cases I can understand only one video at a time. However the cameras always work in their independent loops without a problem. Call loops shown are introduced through a structure of the event by a record button the camera capture independent loop.

    Attached is the code in question, please ignore my attempts at debugging of the indicators.

    I intend on this expansion to four cameras that supports PCIe-8244.

    I could guess that executes the code AVI in the event loop causes the code runs within the user interface thread, preventing access to the controls while the code is running.

  • Parallel loops in a Subvi RT in real-time and not

    Hi all

    I seem to remember learning (obviously not well enough) on a cRIO (vxworks) that if there were a Subvi with two parallel loops and loop fell asleep due to a wait function the other loop also be forced to sleep as they are executed in the same thread.

    I have a 2 questions:

    (1) is this completely wrong?

    (2) is also true on a normal windows OS and if so how can I test it because I tried and couldn't seem to see this behavior?

    Kind regards

    Steve.

    Hello

    (1) is this completely wrong?

    Not completely. If you have to screw (or loops) set up as a time critical (priority) and the other goes to sleep, the entire wire goes to sleep, so also the other VI (or loop) goes to sleep. But notice that it is only when configured as critical moment!

    (2) is also true on a normal windows OS and if so how can I test it because I tried and couldn't seem to see this behavior?

    Lol if a standby under Windows, just the loop loop sleeps.

    Christian

  • Process multiple files in a single loop

    I'm trying to collect data from several text files that I have in a folder.  Is there a CVI function which could loop through files that contain the data that I need until he crossed all the?  If not, all of the files have a similar name (pucklocation.1, pucklocation.2, etc...).  Is there a way I could handle my cPath variable that I have when I call the functions below for what he didn't, and then increments the following, etc...

    iIsGood = FileSelectPopup ("", "*.txt", ".txt", "Load", VAL_LOAD_BUTTON, 0, 1, 1, 0, cPath);
    If (iIsGood == 1)
    {
    iFileHandle = OpenFile (cPath, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);

    An alternative might be to use MultiFileSelectPopup instead of FileSelectPopup.

Maybe you are looking for

  • Extensions

    Cannot remove GoPhotoIt 1.4 or Torrent Manager 1.1 from my list of Firefox Extensions. I tried everything possible to remove these two extensions. I tried to run FF in Safe Mode, which did not work, I completely uninstalled FF but when I reinstalled

  • Where is the backup places.sqlite?

    FF4 on ubuntu... It seems obvious that FF4 retains a backup copy of places.sqlite and places.sqlite is corrupt or deleted automatically replaces the lost or corrupted file. I need to know exactly where FF maintains this info backup. Anyone know? (I h

  • hp renewal guarantee

    Hello I bought m y Lab of hp in 2011. my warranty was expired. Renewal of so iwant my warrenty.how to my warrant.plz renewal give an idea. Thank you and best regards, Raja kitou

  • Convert Int to byte array.

    Hello I am trying to convert an int to an array of bytes and stumbled upon a solution. However, it is not appropriate for BB/J2ME. byte[] bytes = ByteBuffer.allocate(4).putInt(1695609641).array(); for (byte b : bytes) { System.out.format("0x%x ", b);

  • Good BlackBerry signature error code of key order

    Hello, I want to pay for the license, and when I submit the form I have this message. I don't know if this is the right forum for this problem. The proxy error The proxy server received an invalid response from an upstream server.The proxy server cou