Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 如何从AS3中的函数返回值?然后将than值存储在变量中以将其传递给另一个函数?_Flash_Variables_Function_Return Value - Fatal编程技术网

Flash 如何从AS3中的函数返回值?然后将than值存储在变量中以将其传递给另一个函数?

Flash 如何从AS3中的函数返回值?然后将than值存储在变量中以将其传递给另一个函数?,flash,variables,function,return-value,Flash,Variables,Function,Return Value,我正在尝试切换函数Click return powerData。我需要将powerData存储在一个变量中,并将其传递给另一个函数进行计算 在函数toggleClick中,我将powerData分配给houseArray[e.currentTarget.name.toLowerCase()] 我试着只写返回的powerData,但它破坏了程序 //函数切换单击 function toggleClick(e:MouseEvent) { // Store "Power" Values of H

我正在尝试切换函数Click return powerData。我需要将powerData存储在一个变量中,并将其传递给另一个函数进行计算

在函数toggleClick中,我将powerData分配给houseArray[e.currentTarget.name.toLowerCase()]

我试着只写返回的powerData,但它破坏了程序

//函数切换单击

  function toggleClick(e:MouseEvent) {

// Store "Power" Values of House Objects in Array
   var houseArray:Object = {lightA: 1, lightB: 1, lightC: 1,lightD: 1, lightE: 1,
                             comp: 2,
                             tv: 3,
                             stove: 4,
                             laundry: 5};

   // Store User Power in Variable called powerData
   // The currentTarget will equal powerData
   var powerData:int = houseArray[e.currentTarget.name.toLowerCase()];
   //return powerData;

  trace("movieClip Instance Name = " + e.currentTarget); // [object Comp]
  //trace(houseArray[e.currentTarget.name]); // comp
  trace("using currentTarget: " + e.currentTarget.name); // comp
  trace("powerData: " + powerData); // the amount of power that I clicked on
  //trace("houseArray: " + houseArray[0]); // the 0 index of house array
  trace(houseArray[e.currentTarget.name]); // currentTarget inside Array

   // how to find out which object selected

   if (e.currentTarget.currentFrame == 2)
   {
    e.currentTarget.gotoAndStop(3);
    e.currentTarget.bstate = 1;
   }

   if (e.currentTarget.currentFrame == 4)
   {
    e.currentTarget.gotoAndStop(1);
    e.currentTarget.bstate = 0;
   }

}

为什么不在函数外定义powerData,每次单击后都会更新powerData的值

var powerData:int; function toggleClick(event:MouseEvent):void { powerData = houseArray[e.currentTarget.name.toLowerCase()]; performCalculation(); } function performCalculation():void { // you can use the powerData new value here } var-powerData:int; 函数切换单击(事件:MouseEvent):无效 { powerData=houseArray[e.currentTarget.name.toLowerCase()]; 性能计算(); } 函数performCalculation():void { //您可以在此处使用powerData新值 } 或者只需将powerData值传递给函数参数

var powerData:int; function toggleClick(event:MouseEvent):void { powerData = houseArray[e.currentTarget.name.toLowerCase()]; performCalculation(powerData); } function performCalculation(value:int):void { // access the new value here } var-powerData:int; 函数切换单击(事件:MouseEvent):无效 { powerData=houseArray[e.currentTarget.name.toLowerCase()]; 性能计算(powerData); } 函数性能计算(值:int):无效 { //在此处访问新值 } 要使“return powerData”起作用,函数需要返回int值

function toggleClick(event:MouseEvent):int { return powerData; } 函数切换单击(事件:MouseEvent):int { 返回数据; }
但是我不确定这在您的代码中是如何工作的…

谢谢您的回复。我在想,就像“米栏”问题一样——我需要一个customEventListener。在customEventListener内部,将传递powerData和按钮状态(开/关)。customEventListener将查看按钮状态是否为开/关,以便查看是否需要加减法,就像“仪表栏”一样。您可以为HouseObjects创建一个类,该类将具有status(开/关)属性和power属性。单击HouseObject按钮后,可以在事件处理程序中检索这两个属性的值。 function toggleClick(event:MouseEvent):int { return powerData; }