我正在使用Actionscript。我在舞台上使用下面的代码有一个视频对象。我想要做的是当用户将鼠标光标悬停在视频对象的边框上时,用户可以将视频对象拖出以增加其大小并放大或反之亦然。
我找不到任何例子如何做到这一点。如果有人知道Actionscript 3我很感激,如果你能帮助我,谢谢。
var cam:Camera = Camera.getCamera();
cam.setMode(350,250,15);
cam.setQuality(0, 85);
cam.addEventListener(StatusEvent.STATUS, statusHandler);
var mic:Microphone = Microphone.getMicrophone();
mic.gain = 50;
mic.rate = 11;
mic.setSilenceLevel(0, 2000);
mic.addEventListener(StatusEvent.STATUS, micStatus);
var vid:Video = new Video();
vid.width = cam.width;
vid.height = cam.height;
vid.x = 15;
vid.y =30;
vid.attachCamera(cam);
addChild(vid);
答案 0 :(得分:0)
伪代码:
vid.addEventListener(MOUSECLICK, function1)
function1
{
removeEventListener(MOUSECLICK, function1)
stage.addEventListener(MOUSE_MOVE, function2)
}
function2
{
vid.addEventListener(MOUSECLICK, function3)
vid.change_scale
}
function3
{
vid.removeEventListener(MOUSECLICK, function3)
stage.removeEventListener(MOUSE_MOVE, function2)
}
其余的很简单 - 只需使用好的代码。
答案 1 :(得分:0)
最好使用某种边界"你说的元素 - 一个悬停视频的简单精灵。您可以使用某种颜色制作,也可以根据需要使用透明 - 没有区别。你甚至可以做一个'#34; draggable"符号。然后使用此代码:
var draggable:Sprite = new Sprite();
draggable.graphics.beginFill(0xFFFFFF, 0); // transparent
draggable.drawRect(vid.x, vid.y, vid.width, vid.height); // adjust it to fit your video
draggable.endFill();
draggable.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
draggable.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
draggable.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
private var _dragging:Boolean;
private var _initialSize:Rectangle;
private var _initialMouse:Point;
private function onMouseDown(e:MouseEvent):void { // begin dragging
// get initial coordinates and dimension
_initialSize = new Rectangle(vid.x, vid.x, vid.width, vid.height);
// get the initial point where the mouse is
// to calculate the difference and so adjust the width/height of the vid
_initialMouse = new Point(e.mouseX, e.mouseY);
_dragging = true;
}
private function onMouseUp(e:MouseEvent):void { // dragging stopped
_dragging = false;
}
private function onMouseMove(e:MouseEvent):void {
if (!_dragging) // no drag, no scale
return;
// calculate the difference between the starting X position of the mouse
// and the current X position of the mouse. then add this difference
// to the initial width
// example: if initial width was 100, and initial mouse was clicked at 50
// after a few frames the current mouse x (e.mouseX) would be 70
// and the calc would be: 100 + (70 - 50) = 120;
vid.width = _initialSize.width + (e.mouseX - _initialMouse.x);
// adjust the size of the draggable element also,
// so you can have it the same size and click it next time properly
// if you use a "draggable" type of button at the bottom of the video
// then adjust the position, not the size
draggable.width = vid.width;
// do the same on y axis :)
// or if you want to preserve the aspect ration, you need to calculate it
// using the _initialSize variable. I'll leave this to you so you can
// put some effort and feel great when you achieve your goal :)
// just calculate the percentage difference from the width (divide)
// and then multiply the height with the same factor.. Good luck!
}
重要的是要知道,只要这段代码能够正常工作,就可能会出现一些错误,因为我在这里编写它并且从未编译过,抱歉这样:)