2012-02-22 5 views
0

次の関数を組み合わせても、別の文字列をbuildUI();関数に渡すにはどうすればよいですか?変数を関数に渡すためにMovieClipのターゲット名を使用する

私は最後に同じことをする2つの関数を持っています。それらは両方とも関数を呼び出して、関数にString値を渡します。この文字列の値は唯一異なるものです。彼らは今、以下のよう

はは私のイベントリスナーと関数です:

female_start.addEventListener(MouseEvent.MOUSE_DOWN, startFemale); 
    male_start.addEventListener(MouseEvent.MOUSE_DOWN, startMale); 


//FUNCTIONS THAT DO THE SAME THING AND BOTH CALL buildUI BUT PASS A DIFFERENT STRING. 
function startMale(event:MouseEvent):void 
     { 

      female_start.removeEventListener(MouseEvent.MOUSE_DOWN, startFemale); 
      male_start.removeEventListener(MouseEvent.MOUSE_DOWN, startMale); 
      var removeMale = new Tween(male_start, "x", Strong.easeInOut, 540,1080, 2, true); 
      var removeFemale = new Tween(female_start, "x", Strong.easeInOut, 0,-540, 2, true); 
//THIS IS THE ONLY DIFFERENCE BETWEEN THE TWO FUNCTIONS 
      buildUI("Male"); 
    } 


function startFemale(event:MouseEvent):void 
      { 

      female_start.removeEventListener(MouseEvent.MOUSE_DOWN, startFemale); 
      male_start.removeEventListener(MouseEvent.MOUSE_DOWN, startMale); 
      var removeMale = new Tween(male_start, "x", Strong.easeInOut, 540,1080, 2, true); 
      var removeFemale = new Tween(female_start, "x", Strong.easeInOut, 0,-540, 2, true); 
//THIS IS THE ONLY DIFFERENCE BETWEEN THE TWO FUNCTIONS 
      buildUI("Female"); 
    } 

答えて

1
female_start.addEventListener(MouseEvent.MOUSE_DOWN, function(e){start(e, "female");}); 
male_start.addEventListener(MouseEvent.MOUSE_DOWN, function(e){start(e, "male");}); 
function start(event:MouseEvent, sex:String):void{ 
    //do all the stuff 
    buidUI(sex); 
}
関連する問題