A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: get array position from dinamic child

  1. #1
    Member
    Join Date
    Jan 2003
    Location
    portugal
    Posts
    40

    get array position from dinamic child

    hi,

    other problem...
    i'm fighting hard with as3....

    i created a list of textfields as a child each one... from a xml file.
    what i realy want as result of this.... is create a menu with this list... and each text field when clicked invoke specific function that must use some parameters from the respective node in tha xml file too....

    i have the array cursos[..] (each one respects to a new created child)


    A PIECE OF THE CODE FOR EXAMPLE
    cursosTeatroXML = new XML(e.target.data);
    var cursos:Array = new Array();

    for (var c:int = 0; c<cursosTeatroXML.CURSO.length(); c++) {

    cursos[c] = new TextField();
    cursos[c].text = cursosTeatroXML.CURSO[c].DESIGNACAO;
    cursos[c].width = 165;
    cursos[c].selectable = false;
    cursos[c].x = 0;
    cursos[c].y = 30+12*c;
    cursos[c].name = 'opcaoteatro';
    cursos[c].addEventListener(MouseEvent.CLICK, mostraHorario);

    addChild(cursos[c]);

    function mostraHorario() {
    trace (cursosTeatroXML.CURSO[c].DIAS);
    }
    }

    };

    SO the problem is that into the fucntion mostraHorario() i can't reference the XML node needed... also associated to the cursos[c] array item. Even i can pass tha value of 'c' into the function... its value will be tha last one of the for() loop.... and not the respective to the child clicked.

    i'm dispairing width this during too much hours.... trying so many possible solutions... but nothing works...

    thanks.
    caugusto

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    try using a functor - a function that returns a function
    PHP Code:
    cursosTeatroXML = new XML(e.target.data);
    var 
    cursos:Array = new Array();

    for (var 
    c:int 0c<cursosTeatroXML.CURSO.length(); c++) {

    cursos[c] = new TextField();
    cursos[c].text cursosTeatroXML.CURSO[c].DESIGNACAO;
    cursos[c].width 165;
    cursos[c].selectable false;
    cursos[c].0;
    cursos[c].30+12*c;
    cursos[c].name 'opcaoteatro';
    //  pass the functor with the argument
    cursos[c].addEventListener(MouseEvent.CLICKmostraHorario(cursosTeatroXML.CURSO[c].DIAS));

    addChild(cursos[c]);

    // pass the argument to an anonymouse function
    function mostraHorario(arg) {
    return function(){
    trace (arg);
    }
    }
    }

    }; 

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