如何使用FLASH中的actionscript 2创建鼠标交互。 以下是我的as3。我想降级as2。任何人都可以帮我解决这个问题? 另外我想知道我们能否在AS2中做到。我是闪光灯的第一人。
import flash.events.Event;
import flash.events.MouseEvent;
var w:int = 300;
var h:int = 250;
var mdist:int = _bg.width - w;
var mdisty:int = _bg.height - h;
var coef:Number = 0.1;
var autoX:Number = - mdist;
var autoSpeed:Number = ( mdist / (24 * 15) );// (distance in pixel / (fps * secs);
var autoMove:Boolean = true;
var autoDirection:int = 1;
stage.addEventListener(MouseEvent.MOUSE_OUT, stage_MouseOut);
stage.addEventListener(MouseEvent.MOUSE_OVER, stage_MouseOver);
this.addEventListener(Event.ENTER_FRAME, this_EnterFrame);
this.addEventListener(MouseEvent.CLICK, this_Click);
this.buttonMode = true;
_bg.x = - mdist;
_bg.y = - mdisty >> 1;
_copy.mouseEnabled = false;
_copy.mouseChildren = false;
_logo.mouseEnabled = false;
_logo.mouseChildren = false;
function this_EnterFrame(e:Event):void {
if (autoMove) {
_bg.x = autoX;
_bg.y += (-mdisty / 2 - _bg.y) * 0.2;
autoX += autoSpeed * autoDirection;
if (autoX > 0 && autoDirection == 1) {
autoX = 0;
autoDirection = -1;
} else if (autoX < -mdist && autoDirection == -1) {
autoX = - mdist;
autoDirection = 1;
}
} else {
moveScene(mouseX, mouseY);
}
}
function moveScene(px:int, py:int):void {
var xx:int = Math.min(w,Math.max(0,px));
var yy:int = Math.min(h,Math.max(0,py));
var dx:Number = xx / w;
var dy:Number = yy / h;
_bg.x += (-mdist * dx -_bg.x) * 0.2;
_bg.y += (-mdisty * dy -_bg.y) *0.2;
}
此致 HH
答案 0 :(得分:1)
var coef:Number = 0.1;
var autoX:Number = - mdist;
var autoSpeed:Number = ( mdist / (24 * 15) );// (distance in pixel / (fps * secs);
var autoMove:Boolean = true;
var autoDirection:int = 1;
var mouseListener:Object = new Object();
mouseListener.onMouseOut = function():Void
{
}
mouseListener.onMouseOver = function():Void
{
}
mouseListener.onMouseUp = function():Void
{
}
stage.addListener(mouseListener);
_bg.x = -mdist;
_bg.y = -mdisty >> 1;
_copy._enabled = false;
_logo._enabled = false;
stage.onEnterFrame = function ()
{
if (autoMove) {
_bg.x = autoX;
_bg.y += (-mdisty / 2 - _bg.y) * 0.2;
autoX += autoSpeed * autoDirection;
if (autoX > 0 && autoDirection == 1) {
autoX = 0;
autoDirection = -1;
} else if (autoX < -mdist && autoDirection == -1) {
autoX = - mdist;
autoDirection = 1;
}
} else {
moveScene(mouseX, mouseY);
}
}
function moveScene(px:int, py:int):void {
var xx:int = Math.min(w,Math.max(0,px));
var yy:int = Math.min(h,Math.max(0,py));
var dx:Number = xx / w;
var dy:Number = yy / h;
_bg.x += (-mdist * dx -_bg.x) * 0.2;
_bg.y += (-mdisty * dy -_bg.y) *0.2;
}