Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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
Apache flex 错误:类不能嵌套-->;动作脚本_Apache Flex_Actionscript 3 - Fatal编程技术网

Apache flex 错误:类不能嵌套-->;动作脚本

Apache flex 错误:类不能嵌套-->;动作脚本,apache-flex,actionscript-3,Apache Flex,Actionscript 3,我编写了一个actionscript文件includeMyFile.as: package CustomComponent { public class IncludeMyFile extends Object { public function computeSum(a:int, a:int):Number { return a+b; } } } 当我添加包时,我得到一个错误:包不能嵌套 和我的

我编写了一个actionscript文件includeMyFile.as:

package CustomComponent
{
    public class IncludeMyFile extends Object
    {

        public function computeSum(a:int, a:int):Number
        {
            return a+b;
        }
    }
}
当我添加包时,我得到一个错误:包不能嵌套

和我的Mxml文件:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script source="CustomComponent/IncludeMyFile.as"/>  
 <mx:TextInput id="tinput1" width="40" height="40" textAlign="right" 
      x="100" y="100"/>
 <mx:TextInput id="tinput2" width="40" height="40" textAlign="right" 
      x="100" y="100"/>
 <mx:TextArea id="toutput" width="60" height="70" textAlign="right" 
      x="100" y="100"/>

 <mx:Button id="myButton" label="chckSum" 
     click="toutput.text(String(computeSum(Number(tinput1.text),
       Number(tinput2.text)));" x="130" y="140"/>

 <mx:Label text="+" width="40" fontWeight="bold" fontSize="20" x="130" 
      y="140"/>

</mx:Application>

实际上,在这里,我将Actionscript文件包含到MXML中

请告诉我哪里做错了

谢谢, 拉维

你确定你只需要做加法吗

有这样的东西可能更容易:

<mx:Button id="myButton" label="chckSum" click="toutput.text(String(Number(tinput1.text)+ Number(tinput2.text));" x="130" y="140"/>

这只是一目了然。这一切都有点脏,我不知道你到底想做什么

你确定你只需要做加法吗

有这样的东西可能更容易:

<mx:Button id="myButton" label="chckSum" click="toutput.text(String(Number(tinput1.text)+ Number(tinput2.text));" x="130" y="140"/>


这只是一目了然。这一切都有点脏,我不知道你到底想做什么。

这就是导致错误的原因:

<mx:Script source="CustomComponent/IncludeMyFile.as"/>

现在,方法
computeSum
是mxml文件声明的类的实例方法。

这就是导致错误的原因:

<mx:Script source="CustomComponent/IncludeMyFile.as"/>
现在,方法
computeSum
是您的mxml文件声明的类的实例方法。

为未来的Google用户添加我关于此错误的发现。。 除了上面的答案之外,这个错误可能是一个非常小的语法错误的结果,编译器没有像您预期的那样通知您

例如:

public function myFunc(myVar:String=null):void{
  if(myVar==null){
    myVar : String = "Error";
  }
}
请注意,第二个“:String”不是必需的,实际上是触发此编译器错误的语法错误

此错误消息的其他情况:

  • 缺少分号
  • mxml参数中过度使用内联变量
  • 名称空间的双重导入
  • 解决这个问题的最佳人选可能是首先编写错误代码的人。就像在干草袋里发现一根针

    祝你好运

    为未来的谷歌用户添加我关于这个错误的发现。。 除了上面的答案之外,这个错误可能是一个非常小的语法错误的结果,编译器没有像您预期的那样通知您

    例如:

    public function myFunc(myVar:String=null):void{
      if(myVar==null){
        myVar : String = "Error";
      }
    }
    
    请注意,第二个“:String”不是必需的,实际上是触发此编译器错误的语法错误

    此错误消息的其他情况:

  • 缺少分号
  • mxml参数中过度使用内联变量
  • 名称空间的双重导入
  • 解决这个问题的最佳人选可能是首先编写错误代码的人。就像在干草袋里发现一根针


    祝你好运

    这是我找到的唯一能真正解释原因的答案。我的解决方案是不使用
    script
    标记包含脚本,并在必要时导入包。这是我找到的唯一能够真正解释原因的答案。我的解决方案是不使用
    script
    标记包含脚本,并在必要时导入包。谢谢。我记得我不讨厌我的工具。非常感谢。
    public function myFunc(myVar:String=null):void{
      if(myVar==null){
        myVar : String = "Error";
      }
    }