A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: functions and push()

  1. #1
    Junior Member
    Join Date
    Aug 2001
    Posts
    7
    I am trying to make my function push into an array

    The array has already been declared.

    _root.all_user_templ = new Array();


    //User Templates
    function user_templ(user_templ_name)
    {this.user = [user_templ_name];
    _root.all_user_templ.push(this.user);}


    my button action, which is in the same frame, same movie--main timeline.


    on (release) {
    user_templ_name = "name"+_root.i;
    user_templ(user_templ_name); //call function
    // user = [user_templ_name];
    // _root.all_user_templ.push(user);
    test = _root.all_user_templ[_root.i][0];
    _root.i++;
    }


    you'll notice the commented out lines. with these lines enabled, the procedure works, but it also bypasses the function.

    how can I get the function to perform the push??

    thanks,

  2. #2
    Blood elf, or PHP guru... hmmm Paradoxz's Avatar
    Join Date
    Aug 2001
    Location
    Califorina
    Posts
    589
    user_templ_name = "name"+_root.i;

    I didn't completely understand.. I dont know if your haveing a problem, or had a question.. but if it's a problem, then is "name" supposed to be an expression, or not? Try it without the ""

    -Paradoxz

  3. #3
    Junior Member
    Join Date
    Aug 2001
    Posts
    7
    yes, I am having a problem.

    The function does not push the array
    this.user = [user_templ_name]
    into the
    _root.all_user_templ array

    The function should create a multidimensional array, but it does not.


    "name" is my test string, so it needs the ""

    user_templ_name
    is where I put "name"+i, then pass it to the function.

    but the function does not create the array so I can verify
    _root.all_user_templ[_root.i][0]


  4. #4
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    [user_blah_blah] is NOT the same as
    this[user_blah_blah]
    this[user_blah_blah] will evaluate what's in the [ ]..Yours will..do nothing!
    By the way..naming a variable outside the function the same name as the function parameter makes things MUCH more confusing... (but maybe I'm just picky )

    Arctic

  5. #5
    Junior Member
    Join Date
    Aug 2001
    Posts
    7

    functions and push() part 2

    ok, so x not being the same as this.x, I have modified the script, but still there is no action happening. Almost like the function is not actually being called. I tried referenceing the function through _root.user...., but nothing happens there either.

    here is my code again, slightly modified.

    BUTTON
    //this button is located on frame 1 of _root

    on (release) {

    //declare name
    //set to "name0"
    //successive button hits increment "name"
    //"name1", "name2", etc.

    name = "name"+_root.i;

    //call function, send name as parameter

    user_templ(name);

    //set text field variable test to
    test = _root.all_user_templ[_root.i][0];

    //increment i
    _root.i++;
    }
    //end BUTTON


    //this function is located on frame 1 of _root

    //user_templ_name becomes local variable ??

    function user_templ(user_templ_name)

    //create new Array, user_templ_name is first element

    {template = [user_templ_name];

    //push template Array into existing another Array
    _root.all_user_templ.push(template);}

    //exit function



    help...

  6. #6
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    What is it you want to happen?
    trace(_root.all_user_templ[_root.i][0])
    in your function returns
    name0
    name1
    and so on, and the text field returns the same value.
    Make sure you named your text field "test" and it's in the main timeline.
    ALSO: make sure you have
    _root.all_user_templ = new Array()
    as the first line in Frame1 (or anywhere before you define your function)

    Arctic

  7. #7
    Junior Member
    Join Date
    Aug 2001
    Posts
    7

    exactly what I want, exactly what I did

    but it's still not working.

    I'm stumped.

  8. #8
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    If it gives you an error when you start, it's because you have

    function myFunction(parameter)
    {statement
    block}

    rather than

    function myFunction(parameter) {
    statement
    block
    }

    That's the only other thing I can think of..

  9. #9
    Junior Member
    Join Date
    Aug 2001
    Posts
    7

    Thanks Arctic

    It's working.


    I had alot of other functions defined also, and was just testing this one to make sure my structure was correct.

    I deleted everything else except what I needed to test this function, and now it works.

    Something somewhere else was getting in the way of this function working, but I don't know what. It makes use of no other functions.

    Anyway,

    Thank you for working through this with me.

  10. #10
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    Always glad to help..when I can, that is

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center