使用 AS3 AIR 在移动设备上滚动?
Posted
技术标签:
【中文标题】使用 AS3 AIR 在移动设备上滚动?【英文标题】:Scrolling on mobile devices using AS3 AIR? 【发布时间】:2019-12-14 23:57:46 【问题描述】:我已将 XML 调用按钮生成到影片剪辑中。
这是代码
import flash.display.MovieClip;
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.geom.Rectangle;
import flash.utils.getTimer;
import flash.events.MouseEvent;
import flash.text.*;
import flash.display.*;
TweenPlugin.activate([ThrowPropsPlugin]);
var Buttons = new Button_mc();
var across: int = 2;
function generatebtn()
for (var i = 0; i < buttonno; i++)
Buttons = new Button_mc();
Buttons.name = "Button" + i;
Buttons.TypeofQuestions.text = Gk_mc.storeQuesType[i];
var row: int = Math.floor(i / across);
var col: int = i % 2;
MyMovieClip.mc_2.addChild(Buttons);
Buttons.x = col * (Buttons.width) + 25;
Buttons.y = row * (Buttons.height);
Buttons.buttonMode = true;
Buttons.addEventListener(MouseEvent.CLICK, accessclicking);
function accessclicking(e: Event): void
trace(e.currentTarget.name);
generatebtn();
按钮点击事件可以正常工作。
当我添加更多代码时,单击功能的按钮不起作用。见以下代码:
// ----- set up masking boundary for list ------ //
var bounds: Rectangle = new Rectangle(0, 0, MyMovieClip.mc_2.width, 600);
var blitMask: BlitMask = new BlitMask(MyMovieClip.mc_2, bounds.x, bounds.y, bounds.width, bounds.height, false);
var t1: uint, t2: uint, y1: Number, y2: Number, yOverlap: Number, yOffset: Number;
blitMask.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event: MouseEvent): void
TweenLite.killTweensOf(MyMovieClip.mc_2);
y1 = y2 = MyMovieClip.mc_2.y;
yOffset = this.mouseY - MyMovieClip.mc_2.y;
yOverlap = Math.max(0, MyMovieClip.mc_2.height - bounds.height);
t1 = t2 = getTimer();
MyMovieClip.mc_2.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
MyMovieClip.mc_2.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
function mouseMoveHandler(event: MouseEvent): void
var y: Number = this.mouseY - yOffset;
// ----- mc's position exceeds the bounds, make it drag only half as far with each mouse movement (like iPhone/iPad behavior) ------ //
if (y > bounds.top)
MyMovieClip.mc_2.y = (y + bounds.top) * 0.5;
else if (y < bounds.top - yOverlap)
MyMovieClip.mc_2.y = (y + bounds.top - yOverlap) * 0.5;
else
MyMovieClip.mc_2.y = y;
blitMask.update();
var t: uint = getTimer();
// -----If the frame rate is too high, we won't be able to track the velocity as well, so only update the values 20 times per second ------ //
if (t - t2 > 50)
y2 = y1;
t2 = t1;
y1 = MyMovieClip.mc_2.y;
t1 = t;
event.updateAfterEvent();
function mouseUpHandler(event: MouseEvent): void
MyMovieClip.mc_2.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
MyMovieClip.mc_2.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
var time: Number = (getTimer() - t2) / 1000;
var yVelocity: Number = (MyMovieClip.mc_2.y - y2) / time;
ThrowPropsPlugin.to(MyMovieClip.mc_2,
throwProps:
y:
velocity: yVelocity,
max: bounds.top,
min: bounds.top - yOverlap,
resistance: 300
,
onUpdate: blitMask.update,
ease: Strong.easeOut
,
10, 0.3, 1);
/* Drag and Drop
Makes the specified symbol instance move-able with drag and drop.
*/
MyMovieClip.mc_2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
function fl_ClickToDrag(event: MouseEvent): void
MyMovieClip.mc_2.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event: MouseEvent): void
MyMovieClip.mc_2.stopDrag();
滚动正常,但我想通过点击按钮进行滚动 这是6个月前的一个长期问题,但仍未解决。
【问题讨论】:
似乎 blitMask 对象是一个视觉透明的东西,悬停在可滚动的内容上,对吧? 是的,blitMask 对象是一个视觉透明的东西,悬停在可滚动内容上,我想做滚动和点击按钮。 嗯,你应该设计一些其他的滚动方式。 blitMask 对象拦截所有鼠标事件,也包括点击,并且不让它们通过下方的按钮。你有它。 给我的源代码。或任何其他简单的方法来解决它。 【参考方案1】:我将假设您的按钮位于 blitMask
下方。
您可以通过将DisplayObject
的mouseEnabled
属性设置为false
来使鼠标事件通过任何DisplayObject
blitMask.mouseEnabled = false;
【讨论】:
看这个link 我想在每个按钮中使用 MouseEvent 滚动以上是关于使用 AS3 AIR 在移动设备上滚动?的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Adobe air 在静音模式下检测设备并与之交互 - AS3