AS3 Pass parameter by value

Posted by alejandrobog on Stack Overflow See other posts from Stack Overflow or by alejandrobog
Published on 2010-05-06T21:04:41Z Indexed on 2010/05/06 21:08 UTC
Read the original article Hit count: 191

Filed under:
|

Hi, im having problems with the following code:

for (var i:Number=0; i<numFaces;i++){
    var faceLoader:Loader = new Loader();
    faceLoader.contentLoaderInfo.addEventListener( Event.INIT, 
    function(fle:Event){
        LoadCara(i,faceLoader);
        trace("LoadCara:" + i.toString());
    } );
}

function LoadCara(index:int,loader:Loader){
  if(index == 0)
  {
    trace("cara1:" + index.toString());
    cara1.removeChildAt(0);
    cara1.addChild(loader);
  }
  else if(index == 1)
  {
    cara2.removeChildAt(0);
    cara2.addChild(loader);
  }}

The problem is that im sending the variable i to the function LoadCara on every iteration, and its always called with the last value of i. I would like this function to be called with the appropiate index.

Hope I explain myself, thanks in advance.

© Stack Overflow or respective owner

Related posts about as3

Related posts about flash