Actionscript 3 闪存转换工具-工具上未显示控件
我的转换工具的控件出现问题。当我单击我的图像时,我得到了边界框(用于缩放或旋转图像),但当我将鼠标悬停在角落上时,我没有得到光标来变换它 我正在使用这些文件: 这是我调用转换工具的代码:Actionscript 3 闪存转换工具-工具上未显示控件,actionscript-3,flash,transform,scaletransform,Actionscript 3,Flash,Transform,Scaletransform,我的转换工具的控件出现问题。当我单击我的图像时,我得到了边界框(用于缩放或旋转图像),但当我将鼠标悬停在角落上时,我没有得到光标来变换它 我正在使用这些文件: 这是我调用转换工具的代码: var tool:TransformTool = new TransformTool(); addChild(tool); 这将在稍后使工具在单击图像时显示,并在单击舞台时使工具消失: tmpImage.addEventListener(MouseEvent.CLICK, select);
var tool:TransformTool = new TransformTool();
addChild(tool);
这将在稍后使工具在单击图像时显示,并在单击舞台时使工具消失:
tmpImage.addEventListener(MouseEvent.CLICK, select);
function select(e:MouseEvent):void {
tool.target = e.currentTarget as Sprite;
stage.addEventListener(MouseEvent.MOUSE_DOWN, deselect);
}
function deselect(e:MouseEvent):void {
tool.target = null;
tmpImage.addEventListener(MouseEvent.CLICK, select);
}
我为边界框选择的图像显示和消失效果完美。我所有的代码都按预期工作。。。。边界框上的实际控件除外。请帮忙
编辑
其概念是用户可以从菜单中单击图像,然后将该图像的新实例拖动到舞台上。然后,用户可以单击新实例,并且应该能够旋转或缩放它。然后,他们可以单击图像以使边界框消失。(他们可以在舞台上添加任意数量的图像)
下面是一些代码,显示了我实现的基本单击、创建新实例和拖动过程
//sb1 is the menu area that contains a group of images
//hill is one of the images the user can add to the stage
sb1.hill.addEventListener(MouseEvent.MOUSE_DOWN, createCopy);
var i:int=0;
var tmpImage:Sprite; //to store which image is being dragged currently
function createCopy(e:MouseEvent):void {
tmpImage = new Hill_mc();
tmpImage.name = "hillChild"+(i++); //increment every copy
container.addChild(tmpImage);
tmpImage.x = mouseX-470;
tmpImage.y = mouseY-270;
tmpImage.startDrag();
tmpImage.addEventListener(MouseEvent.MOUSE_DOWN, onDown); //add the mouse down to this new object
stage.addEventListener(MouseEvent.MOUSE_UP, onUp); //since the mouse is currently down, we need to listen for mouse up to tell the current copy to stop dragging
}
//this will be called when click a copy
function onDown(e:MouseEvent):void {
tmpImage = Sprite(e.currentTarget); //get a reference to the one that was clicked, so we know which object to stop dragging on the global mouse up.
container.addEventListener(MouseEvent.MOUSE_UP, onUp); //listen for the mouse up
tmpImage.startDrag();
}
function onUp(e:MouseEvent):void {
container.removeEventListener(MouseEvent.MOUSE_UP,onUp);
if (tmpImage.hitTestObject(thesubmenu1)) {
container.removeChild(tmpImage);
}
else {
tmpImage.stopDrag();
}
tmpImage.addEventListener(MouseEvent.CLICK, select);
}
function select(e:MouseEvent):void {
tool.target = e.currentTarget as Sprite;
tmpImage.addEventListener(MouseEvent.MOUSE_DOWN, deselect);
}
function deselect(e:MouseEvent):void {
tool.target = null;
tmpImage.addEventListener(MouseEvent.CLICK, select);
}
编辑
我找到了这段代码并将其放在我的TransformTool.as中。我觉得它太接近了,一定有什么调用不正确,因为我得到了一个空对象引用的错误:
public function select(event:Event):void {
// the selected object will either be the
// event target or current target. The current
// target is checked first followed by target.
// The parent of the target must match the
// parent of the tool to be selected this way.
if (event.currentTarget != this
&& event.currentTarget.parent == parent){
setTarget(event.currentTarget as DisplayObject, event);
}else if (event.target != this
&& event.target.parent == parent){
setTarget(event.target as DisplayObject, event);
}
}
/**
* Helper selection handler for deselecting target objects. Set this
* handler as the listener for an event that would cause the
* deselection of a target object.
* It is not required that you use this event handler. It is only a
* helper function that can optionally be used to help ease
* development.
*/
public function deselect(event:Event):void {
if (_target != null && event.eventPhase == EventPhase.AT_TARGET){
setTarget(null, null);
}
}
您提供的信息太少,无法确定到底是哪里出了问题。 但是,这里有一个非常好的示例代码,它完全符合您的要求: (单击图像底部的链接。) 我相信你会成功的 编辑: 尝试使用内置的处理程序。我会这样做: 与此相反:
tmpImage.addEventListener(MouseEvent.CLICK, select);
function select(e:MouseEvent):void {
tool.target = e.currentTarget as Sprite;
stage.addEventListener(MouseEvent.MOUSE_DOWN, deselect);
}
function deselect(e:MouseEvent):void {
tool.target = null;
tmpImage.addEventListener(MouseEvent.CLICK, select);
}
这样做:
tmpImage.addEventListener(MouseEvent.MOUSE_DOWN, tool.select);
stage.addEventListener(MouseEvent.MOUSE_DOWN, tool.deselect);
编辑:
如果您没有处理程序,我不确定:),但我建议在每个方法中删除事件侦听器,因为它们可能相互干扰
tmpImage.addEventListener(MouseEvent.CLICK, select);
function select(e:MouseEvent):void {
tmpImage.removeEventListener(MouseEvent.CLICK, select);
tool.target = e.currentTarget as Sprite;
stage.addEventListener(MouseEvent.MOUSE_DOWN, deselect);
}
function deselect(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_DOWN, deselect);
tool.target = null;
tmpImage.addEventListener(MouseEvent.CLICK, select);
}
我想你在舞台上增加了一个mousevent监听器。因此,如果你点击图像或舞台上的任何其他东西,取消选择功能就会启动。尝试在tmpImage对象本身上添加鼠标向下侦听器。不过,我希望这样。当前,用户单击图像并获取边界框。然后,如果他们完成了旋转/缩放(如果我可以让控件显示并工作),他们可以单击其他任何位置以取消选择图像。当我在tmpImage上取消选择时,它会循环并保持选中状态。这不是我想要的功能。我希望用户能够单击图像,查看边界框,进行他们想要的编辑,并在完成后单击关闭图像。但该边界框上的控件不显示:(如果你能在TransformTool.com上查看818的代码,你会发现他们已经将eventlisteners添加到了stage。这可能是原因。我想使用函数来取消选择TransformTool.asI中的图像。我已经在我的问题中添加了一些代码。你提供的链接是我找到的工具的第一个实例。我首先使用了这些文件,但是hen使用基本的源代码进行了进一步的研究。我非常接近,哈哈!我以前尝试过这个方法,但我遇到了一个错误:ReferenceError:error#1069:Property select未在com.seneyal.display.transform.TransformTool上找到,并且没有默认值。at Seal()我在TransformTool.as中没有看到select和deselect调用。我只是将上面的内容添加到该.as文件中吗?