Creating function in a loop

hello --
my problem is that i am dynamically creating a bunch of
buttons in a loop, and want to include a different "onRollOver"
function for each button. However, the variables I am setting in
the functions are all being overwritten with the value from the
last pass through the loop. How can i generate a different body of
the function for each button that I'm generating?
my code:
var dataindex=0;
[while loop]
var bname = "instbut_"+dataindex;
var button = container.createEmptyMovieClip(bname,
100+dataindex);
container[bname].onRollOver = function() { trace("my button
name is "+bname); }
dataindex++;
when this runs, it correctly generates four buttons -- but
when i roll over each, "bname" is always equal to "instbut_3". how
can i force it to generate four separate functions, instead of one
single one referenced by all the buttons together?
thanks for any tips!
-- miranda

var dataindex=0;
[while loop]
var bname = "instbut_"+dataindex;
var button = container.createEmptyMovieClip(bname,
100+dataindex);
button.myName = bname;
container[bname].onRollOver = function() { trace("my button
name is "+this.myName); }
dataindex++;
By the way, you could use this._name instead, but for other
variables, give the value you need before writing the event
handler, and then target the values with this.

Similar Messages

  • Calling Function in a loop for CM

    Hi,
    I have the program to create Credit Memo with user selected records. It is working if the user selects any one customer and it will create CM for that customer. But now user wants to select different customers and based on each different vkorg vtweg spart kunnr it has to create different Credit Memo's. How should I put the function in the loop so that it creates different CM's based on each customer.
    Please help me.
    Thanks,
    Neelu.
    AT USER-COMMAND.
      CASE sy-ucomm.
        WHEN 'CMEMO'.
          DESCRIBE TABLE gt_zprice LINES lv_cnt.
          DO lv_cnt TIMES.
            lv_index = sy-index + 1.
            READ LINE lv_index FIELD VALUE chbox.
            IF chbox = 'X'.
              READ TABLE gt_zprice INTO gs_zprice1 INDEX sy-index.
              IF sy-subrc EQ 0.
                gs_zprice1-index = sy-index.
                APPEND gs_zprice1 TO gt2_zprice.
                CLEAR gs_zprice1.
              ENDIF.
            ENDIF.
            CLEAR chbox.
          ENDDO.
          gt4_zprice[] = gt2_zprice[].
    *      SORT gt2_zprice BY vkorg vtweg spart kunnr.
    *      DELETE ADJACENT DUPLICATES FROM gt2_zprice
    *                      COMPARING vkorg vtweg spart kunnr.
    *      DESCRIBE TABLE gt2_zprice LINES lv_lines.
    *      IF lv_lines = 1.
              LOOP AT gt4_zprice INTO gs_zprice1.
                AT NEW kunnr.
                  MOVE 'Y' TO lv_flg.
                ENDAT.
                IF lv_flg EQ 'Y'.
                  PERFORM headerdata.
                  PERFORM texts.
                  CLEAR lv_flg.
                ENDIF.
                PERFORM itemdata.
                APPEND gs_zprice1 TO gt3_zprice.
                CLEAR gs_zprice1.
              ENDLOOP.
              lv_itemno = 10.
              PERFORM call_function.
              PERFORM update_pricetable.
              PERFORM errorcheckandcommit.
              PERFORM displaydata.
              REFRESH gt2_zprice.
              CLEAR chbox.
              CLEAR lv_lines.
              REFRESH partner.
              REFRESH item.
              REFRESH itemx.
              REFRESH lt_schedules_in.
              REFRESH lt_schedules_inx.
              REFRESH conditions1.
              REFRESH order_text.
            ELSE.
              REFRESH gt2_zprice.
              CLEAR chbox.
              EXIT.
            ENDIF.
      ENDCASE.

    call the credimemo create routines at end of kunnr inside the loop.
    LOOP AT gt4_zprice INTO gs_zprice1.
                AT NEW kunnr.
                  MOVE 'Y' TO lv_flg.
                ENDAT.
                IF lv_flg EQ 'Y'.
                  PERFORM headerdata.
                  PERFORM texts.
                  CLEAR lv_flg.
                ENDIF.
                PERFORM itemdata.
                APPEND gs_zprice1 TO gt3_zprice.
                CLEAR gs_zprice1.
    <b>at end of kunnr.
          PERFORM call_function.
              PERFORM update_pricetable.
              PERFORM errorcheckandcommit.
              PERFORM displaydata.
              REFRESH gt2_zprice.
              CLEAR chbox.
              CLEAR lv_lines.
              REFRESH partner.
              REFRESH item.
              REFRESH itemx.
              REFRESH lt_schedules_in.
              REFRESH lt_schedules_inx.
              REFRESH conditions1.
              REFRESH order_text.
    endat.</b>
              ENDLOOP.
              lv_itemno = 10.
           ELSE.
              REFRESH gt2_zprice.
              CLEAR chbox.
              EXIT.
            ENDIF.
      ENDCASE.

  • Functions in a Loop

    I'm trying to create multiple Functions inside a Loop. Can I not do this?
    for (var i:Number = 1; i<5; i++)
      function this["closeButOut"+i](event:MouseEvent)
                                  closeBar["but0" + i].gotoAndStop(1);
    I essentially want to make 4 Functions called closeButOut1, closeButOut2, closeButOut3 and closeButOut4.
    This is the error message I get:
    1084: Synax error: expecting identifier before this.
    1084: Syntax error: expecting leftparen before rightbracket.

    Sorry, it should look like this:
    for (var i:Number = 1; i<5; i++)
    closeBar["but0" + i].addEventListener(MouseEvent.ROLL_OUT, this["closeButOut"+i])
      function this["closeButOut"+i](event:MouseEvent)
                                  closeBar["but0" + i].gotoAndStop(1);
    When I tried your change, it seemed to accept it, but the listener doesn't recognize it as the same function it's looking for.

  • How to use select a vi function inside a loop?

    I am modifying the notifier basics part 2.vi to send a notifier to each of 64 sub-vi's. How can you use the 'select a vi' function inside a loop for 64 iterations to access the individual filenames??
    Attachments:
    Notifier_BASICS_Part_2.vi ‏87 KB

    If all you are trying to do is send notifiers to each of these 64 subVIs, I would suggest not doing it in a loop, but rather just placing the 64 subVIs in your diagram.
    The alternative is of course to use the call by reference node and have an array of VI names. This is a little cleaner on the diagram, but 1) doesn't occur in parallel and 2) is a bit tricky. Additionally, you have to be sure that your array of filenames is correct, and that you NEVER move or rename those VIs. Of course, you could always put them in a directory and create an array by reading the directory contents.
    Either way, good luck, it doesn't sound like fun.

  • Requried Help in creating function

    Hi All,
    i need one help in creating function my input parameters for that function will be 1 or 1,2 or 1,2,3
    my output should be
    If i pass as 1 as input parameter it should return 1
    If i pass 1,2 as input parameter it should return 1,2 in different rows
    Similarly If i pass 1,2,3 as input parameter it should return 1,2,3 in different rows.
    Can any one please help me in creating this function.
    Thanks in Advance.
    Edited by: p78 on Jan 16, 2012 3:31 AM
    Edited by: p78 on Jan 16, 2012 3:31 AM

    Hi,
    that will be something like this. First you need a type for returning the rows (use other datatype for example number if you need so):
    CREATE OR REPLACE TYPE t_list AS TABLE OF VARCHAR2 (4000);
    /Then the function will be a pipelined 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 are):
    select * from table(in_list('aa','bb'));Herald ten Dam
    http://htendam.wordpress.com

  • Create Functional Area via Job Architecture in Non-English language

    Dear Experts,
    We're running following environment.
    - Windows Server 2003 Std SP2 64bit (32bit conversion completed)
    - SAP ERP 6.0 EhP 4 Unicode system as back-end system for STVN
    - STVN 2.1 SP1 with Japanese Language pack
    - Language = Japanese and English
    - TREX setting is not ready (will be ready soon)
    The problem is we cannot create Functional Area via Job Architecture
    if we log on Job Architecture module with JAPANESE.
    (We can create Functional Area if we log on with ENGLISH)
    [Procedure]
    1. Launch Job Architecture module with Japanese
    2. Job Architecture => Create Functional Area (under Tasks)
    3. Key in [Title] and [Abbreviation], and then click [Add]
    4. Error message "Not able to load DLL or CLASS" appears
    I have already confirmed that if I do same thing with English,
    Functional Area was created in ECC environment.
    What settings am I missing?
    Best Regards,
    Masaya Iizumi

    Dear Luke and Eugene
    Thank you very much for the reply.
    I have understood that it is known issue for .NET platform for 2.1 SP1.
    I will communicate with Nakisa Support.
    Again, thank you very much for your kind cooperation.
    Best Regards,
    Masaya

  • Doubt in  export, import and table para when creating Function Module

    Dear fellow ABAPers,
    I have a doubt in defining export, import and table parameter while creating a function module.
    I am calling a function module inside a user exit. Now in the user exit the SAP fills an internal table called i_lfa1 with all the data user has eneterd.
    Now I want to pass this whole internal table to function module and the perform some checks on the values of internal table.
    After that function module fills an error structure with values depending on some check.
    1)
    How do I pass this internal table to function module ? 
    When I am creating function module in se37 where do I define this iternal table type ? Is it in Import or Table parameter during function module creation?
    2)
    Where do I define error structure type (which is returned by function module to main program)? Is it in Export or table parameter during function module creation?
    Please clear my doubt..
    Relevant points will be awarded.
    Regards,
    Tushar.

    Hi Tushar,
    1. How do I pass this internal table to function module ?
       I assume u are creating your own Y/Z FM.
       Pass it thru TABLES parameter.
    2. When I am creating function module in se37 where do I define this iternal table type
       Define this in TABLES interface.
       What Type ?
       THE SAME TYPE WHICH HAS BEEN DEFINED
        WHILE PASSING IN THE USER-EXIT FUNCTION MODULE.
       IF U SEE THE FM OF THE USER-EXIT,
       U WILL COME TO KNOW.
    3.
    Where do I define error structure type (which is returned by function module to main program)? Is it in Export or table parameter during function module creation?
    Define it in TABLES interace. (not in export, import)
      (Since what u are going to return is an internal table)
      U can take for eg. BDCMSGCOLL.
      OR u can create your own Y/Z structure
    for the same purpose.
      (or u can use the structure type T100)
    I hope it helps.
    Regards,
    Amit M.

  • Creating function to calculate average value

    Hi,
    The below query was successfully return an average value. It returned 1 row.
    SELECT AVG(Volume)
    FROM security
    WHERE
    Type = 'Future' AND
    Rating = 'AAA' AND
    Code = 1 AND
    (Day = ''14-mar-09' OR
    Day = '16-mar-09' OR
    Day = '');
    I tried to use that function on my created function below.
    CREATE OR REPLACE FUNCTION fn_Vol_Average
    ( v_DayLast_1_Week IN DATE,
    v_DayLast_2_Week IN DATE,
    v_DayLast_3_Week IN DATE )
    RETURN NUMBER IS
    v_Vol_Average NUMBER;
    BEGIN
    SELECT AVG(Volume) INTO v_Vol_Average
    FROM security
    WHERE
    Type = 'Future' AND
    Rating = '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 that function by the following query. it was work, however it return the whole rows. It looks like the function perform the average calculation of each rows on the table.
    Can anyone help me what is going on with the logic?
    select fn_Vol_average('14-mar-09','16-mar-09','')
    from security
    --

    But since your function calculates the average over the whole security table, you wouldn't call this from a select statement which also reads the security table.
    You just want to execute it once.
    declare
       l_vol_average number;
    begin
       l_vol_average := fn_Vol_average('14-mar-09','16-mar-09','');
       dbms_output.put_line(l_vol_average);
    end;By the way, be careful with your date parameters. You should use TO_DATE with a proper format mask to prevent conversion errors.

  • How to create function module for getting customer name

    Hi Experts,
                   How to create function module?  when in import parameter kunnr values to be passed it must give name1 details according to the customer number...
    how to write the logic in source code....
    Regards,
    Thiru. R

    1. First of all create function group.
    2. Create function module using this function group.
    3. If only one kunnr is needed at a time, create import parameter for it. But if many kunnr to be entered at a time,use table.
    4. Fetch name1 for each kunnr from KNA1 table.
    "->> if many kunnr
    if not t_kunnr[] is initial.
    select kunnr as kunnr name1 as name1
    into table t_kunnr_name1
    from kna1
    for all entried in table t_kunnr
    where kunnr = t_kunnr-kunnr.
    endif.       
    sort t_kunnr_name1 by kunnr name1.
    delete adjacent duplicates from t_kunnr_name1 comparing kunnr name1.
    table t_kunnr_name1 will contain kunnr and its name1.
    I hope logic is clear for you now.
    Regards,
    Aparna

  • Calling a function in a loop

    Hello,
    I have something like this:
             declare
             cursor c is
               select 2,3,4 from dual;
             begin
             for r in c loop
               dbms_output.put_line( prod_stb(81852225, r, 'STB 1 HORECA'));
             end loop;
             end;I wanna call (and output the results) that function in a loop, for all 2,3,4 values for the 2nd parameter.
    How can i do this?
    with simple 'r' in the 2nd parameter does not work
    Thanks!

    So the 2nd parameter should be 2,3 and 4 (in a loop).Well, as far as I understand, that's exactly what you'll get:
    SQL> begin
      2    for r in ( select level+1 col from dual connect by level <= 3 )
      3    loop
      4      dbms_output.put_line( r.col);
      5    end loop;
      6  end;
      7  /
    2
    3
    4
    PL/SQL procedure successfully completed.

  • How to use reverse function in FOR loop

    Hi,
    Can we use REVERSE function in for loop.
    If so can u please give an explanation with some example.
    Thanks in advance.
    Satya.

    In SQL you could do this...
    SQL> ed
    Wrote file afiedt.buf
      1  select empno, ename, replace(sys_connect_by_path(ch,'|'),'|') as rev_ename
      2  from (
      3    select empno, ename, case when rn <= length(ename) then substr(ename, length(ename)-rn+1, 1) else null end as ch, rn
      4    from emp
      5        ,(select rownum as rn from dual connect by rownum <= (select max(length(ename)) from emp))
      6    where case when rn <= length(ename) then substr(ename, length(ename)-rn+1, 1) else null end is not null
      7    )
      8  where connect_by_isleaf = 1
      9  connect by empno = prior empno and rn = prior rn + 1
    10  start with rn = 1
    11* order by empno
    SQL> /
         EMPNO ENAME      REV_ENAME
          7369 SMITH      HTIMS
          7499 ALLEN      NELLA
          7521 WARD       DRAW
          7566 JONES      SENOJ
          7654 MARTIN     NITRAM
          7698 BLAKE      EKALB
          7782 CLARK      KRALC
          7788 SCOTT      TTOCS
          7839 KING       GNIK
          7844 TURNER     RENRUT
          7876 ADAMS      SMADA
          7900 JAMES      SEMAJ
          7902 FORD       DROF
          7934 MILLER     RELLIM
    14 rows selected.
    SQL>

  • Creating function description: "inconsistence in description detected ..."

    In my own NW RFC-SDK based application, I am trying to create a RFC module description the hard way, which is to not download such a description from a SAP system, but to craft the description on-the-fly using API functions RfcCreateFunctionDesc, RfcCreateTypeDesc, RfcAddTypeField, RfcAddParameter and  RfcCreateFunction. When calling RfcCreateFunction the system responds with the message
    "inconsistence in description detected: non-unicode length is too small".
    As far as I can tell all values I provided in the API arguments are correct, including the unicode and non-unicode lengths in the type description of a structure that is underlying the only RFC parameter in the module.
    Here is what the module isi supposed to look like:
    module has only one Export parameter
    the parameter is structured
    the structure has a single field only, which is a character array of length 64 (i.e 128 bytes).
    My application is unicode based. I added some code to the application to trace the API calls along with the argument values. Here is the output:
    API RfcCreateFunctionDesc
    Created function description object; returned handle: 024A1880
    API RfcCreateTypeDesc
    Created type description object; returned handle:     024A1A00
    API RfcAddTypeField
    Added Field to type description 024A1A00:
      name                DEST
      type                0
      nucLength           64
      nucOffset           0
      ucLength            128
      ucOffset            0
      decimals            0
      typeDescHandle      00000000
      extendedDescription 00000000
    API RfcAddParameter
    Added parameter to funtion description 024A1880:
      name                ATTRIBUTES
      type                17
      nucLength           64
      ucLength            128
      decimals            0
      typeDescHandle      024A1A00
      optional            0
      direction           2
      parameterText
      defaultValue
      extendedDescription 00000000
    API RfcCreateFunction
    Created function object from description 024A1880; returned handle:     00000000
    RFC_INVALID_PARAMETER inconsistence in description detected: non-unicode length
    is too small
    Thanks so much for any help!

    Case closed. There was an API call missing in my code, RfcSetTypeLength, which sets the total lengths (unicode and non-unicode) of the structure after adding the structure components.Without that call the system assumes those lengths to be zero, thus the error ...

  • Create function as "/ as sysdba" not shipped/applied to logical standby

    As the subject states, I was creating a password verify function and profile that used the function as sys "/ as sysdba" .
    The function was not created on the logical standby and thus the profile create statement failed. The function was not even listed in the standby's alertlog, although the create profile statement was.
    I created the function manually on the standby by connecting / as sysdba and creating the function and then restarted logical standby apply. The standby then created the profile and continued without error.
    Is this a bug?
    Should the SYS 'create function' be shipped and applied or not?
    When the function create statement was run on the primary as a non-sys user with DBA privs, it created ok and was shipped and appeared on logical standby ok.
    Any ideas DataGuard Gurus?
    (9.2.0.7 on Solaris 8)

    I logged a Tar. Oracle says:
    "Ideally any object created on sys schema should get skipped automatically. sys is consider as internal schema and objects created in sys schema should get
    skipped"
    "But because of the internal Bug.3576307 "LOGICAL STANDBY IS NOT SKIPPING DDL IT SHOULD." it is not skipping the DDL executed on sys schema. This bug
    is fixed in 10.2.
    You can issue following statement to enable the DDL skip on sys schema.
    SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY;
    SQL> EXECUTE DBMS_LOGSTDBY.SKIP_ERROR(‘SCHEMA_DDL’, ‘SYS’, null, null)
    SQL> ALTER DATABASE START LOGICAL STANDBY APPLY;
    After which all DDL errors encountered on any object in the SYS schema would be ignored and processing continued. This can render the TEST schema objects unusable and, if necessary, you can later recreate the tables
    using the INSTANTIATE_TABLE procedure."
    Makes sense now.

  • Creating Functions in SQL server

    HI
    i creating functions for specific purpose in the test database...
    is it against SAP Support policy?
    suggest me...

    if you are just going to start entries then you can .
    But i have posted then Use replace function in SQL
    SQL Syntax:
          REPLACE( string1, string2, string3 ) 
    Parameters:
        string1
    Any character string or binary expression that can contain the string from string2.
    string2
    Any character string or binary expression. This string is searching in string1.
    string3
    Any character string or binary expression. This string replace all occurrence of string2.
    May it will work
    Thanks
    Manvendra Singh Niranjan

  • How to create function panels for my own C functions?

    I've been searching for a way to create my own function panels. CVI documentation seems to suggest that this can be done but the explanation inevitably turns to instrument drivers, not C functions.
    I don't yet know what an instrument driver is. So far I've never needed one. I just want to know how to put plain old C functions that I've created into the library tree for coworkers to use. Is that practically possible?

    The facility is couched in terms of "instrument driver" but it can be used for an arbitrary CVI function you've created.
    First make a function tree from File pull down menu   new ... Function Tree
    Then right click in blank function tree panel and create instrument or use Create pulldown menu, enter name as prompted, use help button.  You need to choose a "prefix" for your function names.
    The tricky part is when you want to add a function to your "instrument" you right click on the <create class or function panel window> token the first time, thereafter when adding a function you right click on one of the functions you've already added.  In either case you want to "create function panel window" which brings up the function panel window editor whcih allows you to place input controls that match the function signature.
    There's a learning curve but keep at it.  The help is good, use it.
    Menchar

Maybe you are looking for

  • Is there better way to do this?  (Xml Pretty Print | node removing)

    Hi all, I have been working at home on a small project to help my Java Jedi training. :-) My app saves quotes from authors in an xml file. I have a class [XmlRepository extends Thread] that holds control of an xml file to handle requests for Nodes. W

  • Why is the Mini Interlacing 1080p?

    Hello All, I recently purchased the prior 2011 Mac Mini with the following specs: 4 GB 1333 MHz DDR3 2.5 GHz Intel Core i5 AMD Radeon HD 6630M 256 MB OS X 10.8.4 I also purchased an Asus 22" LED HD, (1080p) screen (VS229H-P) that I've attached via hd

  • New Excel Features - Use of Integration,Formatting and Formulae in BI 7

    Hi Experts, I had a look at the Excel integration section of the BI 7 Features and found the some new enhancements for Excel.We are planning to upgrade to BI7 and want to get some expert opinions 1. Excel Formulas allow access to any cell of the resu

  • Add music to slideshow

    I can't seem to be able to see my itunes library when trying to add music to a slideshow.  I have tried the help topics but neither method seems to work (e.g. To add music to a slideshow; If you don't see your itunes library in the source popup menu)

  • Development System Backup - Best Practice / Policy for offsite backups

    Hi, I have not found any recommendations from SAP on best practices/recommendations on backing up Development systems offsite and so would appreciate some input on what policies other companies have for backing up Development systems. We continuously