我需要在静态函数中使用鼠标坐标。它不是鼠标事件函数,并且函数中没有传递任何内容。
// Main class
MyClass.something();
// MyClass
public static function something():void
{
// Get Mouse Cordinates
// myclassclip.x = mouse cordinates
}
答案 0 :(得分:1)
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.geom.Point;
public class MyClass extends Sprite
{
private static var _instance:MyClass;
public function MyClass()
{
super();
}
public static function getInstance():MyClass
{
if (!_instance)
_instance = new MyClass();
return _instance;
}
public static function testMouse():Point
{
var myStage:Stage = _instance.stage;
var point:Point = new Point(myStage.mouseX, myStage.mouseY);
return point;
}
}
}
在主要课程中:
// Somewhere in the Main class
addChild(MyClass.getInstance());
// In other place in the Main class
MyClass.testMouse();