Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/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
Actionscript 3 Actionscript-静态函数和UI元素有问题吗?_Actionscript 3_User Interface_Haxe_Static Functions - Fatal编程技术网

Actionscript 3 Actionscript-静态函数和UI元素有问题吗?

Actionscript 3 Actionscript-静态函数和UI元素有问题吗?,actionscript-3,user-interface,haxe,static-functions,Actionscript 3,User Interface,Haxe,Static Functions,在actionscript中使用OOP时,我有点不知所措。我有一个捕获视频流的显示类。我正在尝试创建一组基本的停止/录制按钮来控制相机。显然,我不能声明访问此的函数或任何允许我识别和停止剪辑的变量。编译器(我正在使用Haxe)抛出错误: video/Webcam.hx:96: characters 10-14 : Cannot access this from a static function 我可能走错了路。以下是一些(缩写)代码: 我正在使用Haxe编译到AS3。这里有一个三角洲列表,似

在actionscript中使用OOP时,我有点不知所措。我有一个捕获视频流的显示类。我正在尝试创建一组基本的停止/录制按钮来控制相机。显然,我不能声明访问
的函数或任何允许我识别和停止剪辑的变量。编译器(我正在使用Haxe)抛出错误:

video/Webcam.hx:96: characters 10-14 : Cannot access this from a static function
我可能走错了路。以下是一些(缩写)代码:

我正在使用Haxe编译到AS3。这里有一个三角洲列表,似乎没有涵盖这个问题,所以我相信这是一个问题,我有。它可能与编译器有关,但我希望不是,因为到目前为止我真的很喜欢Haxe


如果actionscript编译器将这些函数视为静态函数,如何创建与对象实例关联的UI元素?

I相信这是由于在MouseEvent中使用了匿名函数。单击处理程序而不使用事件本身。事件处理程序接受一个参数,即MouseEvent本身。因此,您必须执行以下操作之一:

b.addEventListener(flash.events.MouseEvent.CLICK, function($evt:MouseEvent) {
    trace($evt.target.parent);
    $evt.target.parent.stopStream();  // May require casting, but probably not
}
private function addControls(){
  ...
  var self = this;
  b.addEventListener(flash.events.MouseEvent.CLICK,function() { 
    self.stopStream()
  });
  ...
}

b.addEventListener(flash.events.MouseEvent.CLICK, __handleStopClick);

private function __handleStopClick($evt:MouseEvent):void {
    this.stopStream();
}

我认为这是由于在MouseEvent中使用了匿名函数。单击处理程序而不使用事件本身。事件处理程序接受一个参数,即MouseEvent本身。因此,您必须执行以下操作之一:

b.addEventListener(flash.events.MouseEvent.CLICK, function($evt:MouseEvent) {
    trace($evt.target.parent);
    $evt.target.parent.stopStream();  // May require casting, but probably not
}
private function addControls(){
  ...
  var self = this;
  b.addEventListener(flash.events.MouseEvent.CLICK,function() { 
    self.stopStream()
  });
  ...
}

b.addEventListener(flash.events.MouseEvent.CLICK, __handleStopClick);

private function __handleStopClick($evt:MouseEvent):void {
    this.stopStream();
}

另一种常见的方法是:

b.addEventListener(flash.events.MouseEvent.CLICK, function($evt:MouseEvent) {
    trace($evt.target.parent);
    $evt.target.parent.stopStream();  // May require casting, but probably not
}
private function addControls(){
  ...
  var self = this;
  b.addEventListener(flash.events.MouseEvent.CLICK,function() { 
    self.stopStream()
  });
  ...
}

优点是“self”输入正确,不需要强制转换。我们正在考虑在这种情况下添加“this”作为默认范围,这将使“self”技巧变得不必要。

另一种常见的方法是:

b.addEventListener(flash.events.MouseEvent.CLICK, function($evt:MouseEvent) {
    trace($evt.target.parent);
    $evt.target.parent.stopStream();  // May require casting, but probably not
}
private function addControls(){
  ...
  var self = this;
  b.addEventListener(flash.events.MouseEvent.CLICK,function() { 
    self.stopStream()
  });
  ...
}

优点是“self”输入正确,不需要强制转换。我们正在考虑在这种情况下添加“this”作为默认范围,这将使“self”技巧变得不必要。

将对象传递到函数中是非常有意义的。虽然haxe不允许在变量名中使用$,但这两种方法都可以完美地工作(无需强制转换)。非常感谢!将对象传递到函数中是非常有意义的。虽然haxe不允许在变量名中使用$,但这两种方法都可以完美地工作(无需强制转换)。非常感谢!