AS3滚动Movieclip

时间:2014-04-05 13:50:38

标签: actionscript-3 user-interface scroll

我的代码存在问题,因此我有一个衍生的垂直动画片段,其中有按钮实例,使其看起来像一个列表。

问题是我正在尝试重新创建iOS风格的拖动滚动。当我按住并拖动我的movieclip时,它工作正常,上下滚动。但是当我释放鼠标左键时,它会在我的一个按钮上注册一次。

我尝试删除按钮上的事件侦听器,但滚动只能工作一次,在我释放鼠标左键后,整个滚动操作第二次不起作用。

是否有可能像鼠标拖动(向上或向下)忽略按钮单击侦听器,但是当用户想要单击按钮时,滚动不会启动?

我的按钮'类

public function PlaceOneButtons()
    {
            for (var a=0; a<buttons.length; a++)
            {
                stationsone1[a].addEventListener(clicked,StationSelectOne);
                stationsone2[a].addEventListener(clicked,StationSelectOne);
                stationsone3[a].addEventListener(clicked,StationSelectOne);
                stationsone4[a].addEventListener(clicked,StationSelectOne);
                stationsone5[a].addEventListener(clicked,StationSelectOne);
            }

    }

My Main(spawner)class

package 

{

import flash.display.MovieClip;
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.ui.*;
import flash.utils.*;
import flash.media.*;
import IconSpawn;
import Scrolling;


public class MainClass extends MovieClip
{
    private var iconspawn:IconSpawn = new IconSpawn();
    private var touchay:int = new int;
    private var touchPoint:int = new int;
    private var touchPoint2:int = new int;
    private var touchString:int = new int;
    private var AYint:int = new int;
    private var touchTimer:Timer = new Timer(150,1);
    private var endTime:Timer = new Timer(1,1);
    private var speed:int = new int;
    public static var scrollDiff:int = new int;
    public static var doubleDiff:int = new int;
    public static var dragging:Boolean = new Boolean
    //private var scrolling:Scrolling = new Scrolling();
    //public static var Ystore:Point;

    public function MainClass()
    {
        // constructor code
        AYint = IconSpawn.A_Y.y;

    }

    public function startApp()
    {
        addChild(iconspawn);
        iconspawn.MenuSpawn();
        dragging = false;
    }
    public function directionsApp()
    {
        addChild(iconspawn);
        iconspawn.KeyboardOne();
    }
    public function placeOneApp()
    {

        addChild(iconspawn);
        iconspawn.PlaceOneSpawn();
        Evtlistener();
    }
    private function Evtlistener()
    {
        addEventListener(Event.ENTER_FRAME,update);
        addEventListener(MouseEvent.MOUSE_DOWN,spawnTouch);
        addEventListener(MouseEvent.MOUSE_UP,endScroll);
    }
    public function directionsApp2()
    {
        addChild(iconspawn);
        iconspawn.KeyboardTwo();
    }
    public function update(evt:Event)
    {
        //trace(touchTimer);
        //trace(touchString);
        touchPoint2 = mouseY;
        scrollDiff = touchPoint2 - touchPoint;
        doubleDiff = scrollDiff - scrollDiff;
        trace(dragging);
        if(dragging == true)
        {
            //iconspawn.PlaceOneButtons();
        }
    }
    public function spawnTouch(evt:MouseEvent)
    {
        touchPoint = mouseY;
        touchTimer.addEventListener(TimerEvent.TIMER,timerTouch);
        endTime.addEventListener(TimerEvent.TIMER,endTimer);
        touchTimer.start();
        dragging = true;
        touchay = IconSpawn.A_Y.y;

    }
    public function timerTouch(evt:TimerEvent):void
    {
        if(dragging == true)
        {
        addEventListener(Event.ENTER_FRAME,startScroll);
        }
    }
    public function startScroll(evt:Event)
    {
            if(mouseY > 540 && mouseY < 1510)
            {
            IconSpawn.A_Y.y = touchay + (touchPoint2 - touchPoint);
            }

    }
    public function endScroll(evt:MouseEvent)
    {
        removeEventListener(MouseEvent.MOUSE_DOWN,spawnTouch);
        removeEventListener(Event.ENTER_FRAME,startScroll);
        touchTimer.reset();
        endTime.start();

    }
    private function endTimer(evt:TimerEvent):void
    {
        dragging = false;
        Evtlistener();
    }


}

}

帮助将不胜感激!几天来一直坚持这个问题。

更新:添加了新的更新代码

大家好,我现在的问题是,在滚动动画片段之后,如果它的= 0,代码会侦听scrollDiff。

当scrollDiff为0时,动画片段的按钮是可点击的,但如果它多于或少于该按钮,则按钮不可点击。现在我的新问题是,在我释放左键后,代码不会将scrollDiff更新为0,因此用户必须双击才能选择按钮。救命啊!

package 
{

import flash.display.MovieClip;
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.ui.*;
import flash.utils.*;
import flash.media.*;
import IconSpawn;
import Scrolling;


public class MainClass extends MovieClip
{


    private var iconspawn:IconSpawn = new IconSpawn();
    private var touchPoint:int = new int;
    private var touchPoint2:int = new int;
    private var AYint:int = new int;
    private var touchTimer:Timer = new Timer(150,1);
    private var endTimer:Timer = new Timer(150,1);
    private var IconSpwnY:int = new int;
    private var touchbool:Boolean = new Boolean
    public static var scrollDiff:int = new int;
    //private var scrolling:Scrolling = new Scrolling();
    //public static var Ystore:Point;

    public function MainClass()
    {
        // constructor code
    }

    public function startApp()
    {
        addChild(iconspawn);
        iconspawn.MenuSpawn();
    }
    public function directionsApp()
    {
        addChild(iconspawn);
        iconspawn.KeyboardOne();
    }
    public function placeOneApp()
    {

        AYint = IconSpawn.A_Y.y;
        addChild(iconspawn);
        iconspawn.PlaceOneSpawn();
        addEventListener(Event.ENTER_FRAME,update);
        addEventListener(MouseEvent.MOUSE_DOWN,spawnTouch);
        addEventListener(MouseEvent.MOUSE_UP,endScroll);
        touchbool = false;
        //IconSpawn.container.mouseChildren = true;

    }
    public function directionsApp2()
    {
        addChild(iconspawn);
        iconspawn.KeyboardTwo();
    }
    public function update(evt:Event)
    {
        touchPoint2 = mouseY;
        scrollDiff = touchPoint2 - touchPoint;
        trace(scrollDiff);
    }
    public function spawnTouch(evt:MouseEvent)
    {
        touchPoint = mouseY;
        touchTimer.addEventListener(TimerEvent.TIMER,timerTouch);
        touchTimer.start();
        IconSpwnY = IconSpawn.A_Y.y;
        if(scrollDiff == 0)
        {
            IconSpawn.container.mouseChildren = true; //Important <-
        }
        else
        {
            IconSpawn.container.mouseChildren = false; //Important <-
        }

    }
    public function timerTouch(evt:TimerEvent):void
    {
        addEventListener(Event.ENTER_FRAME,startScroll);
        touchbool = true
    }
    public function startScroll(evt:Event)
    {
            if(mouseY > 0 && mouseY < 1510)
            {
            IconSpawn.A_Y.y = IconSpwnY + (touchPoint2 - touchPoint);
            }

    }
    public function endScroll(evt:MouseEvent)
    {
        removeEventListener(MouseEvent.MOUSE_DOWN,spawnTouch);
        removeEventListener(Event.ENTER_FRAME,startScroll);
        endTimer.addEventListener(TimerEvent.TIMER,endTiming);
        endTimer.start();
        trace("CALLL")
        scrollDiff = touchPoint2 - touchPoint;
        //touchTimer.reset();
    }
    private function endTiming(evt:TimerEvent)
    {
        IconSpawn.container.mouseChildren = true;
        addEventListener(MouseEvent.MOUSE_DOWN,spawnTouch);
        //addEventListener(Event.ENTER_FRAME,startScroll);
        scrollDiff = 0;
    }


}

}

2 个答案:

答案 0 :(得分:1)

当你移动集<container_mc>.mouseChildren = false时。当容器剪辑停止移动时,将mouseChildren属性设置为“true”。

答案 1 :(得分:0)

添加到Craig的答案(我绝对建议实现,以使生活更轻松!),这里是您应该为此按计划工作的事件监听器列表。这是理论,所以你可能不得不玩一下。

container.addEventListener(MouseEvent.MOUSE_DOWN, response);:你想要提出一些鼠标停止的标志,并等待下一个鼠标事件,这决定了行动。

container.addEventListener(MouseEvent.MOUSE_MOVE, response);:如果鼠标已关闭,请禁用子项单击(Craig的答案)并开始拖动。你还想提出拖拽标志。

container.addEventListener(MouseEvent.MOUSE_UP, response);:如果引发拖动标记,请停止拖动并启用子项单击。如果它没有被提升,则什么也不做,所以该项目可以从那里接管。

item.addEventListener(MouseEvent.MOUSE_UP, itemResponse);:您的点击操作。

理论上,只要你使用MouseEvent.MOUSE_UP作为它们的监听器(如上所示),这应该适用于嵌套的MovieClip。使用MouseEvent.MOUSE_DOWN或MouseEvent.CLICK可能会弄乱您的计时。但是,我会进行一些实验来找到正确的组合,因为在最后一点我可能错了。

相关问题