2014-04-05 3 views
1

내 코드에 문제가있어서 버튼 인스턴스가있는 것처럼 보이는 곳에서 세로 모양의 무비 클립이 생성됩니다.AS3 스크롤 무비 클립

문제는 iOS 스타일 드래그 스크롤을 다시 만들려고한다는 것입니다. 내 영화 클립을 잡고 드래그하면 위아래로 스크롤하여 잘 동작합니다. 그러나 마우스 왼쪽 버튼을 놓으면 버튼 중 하나에 클릭이 등록됩니다.

나는 버튼에 이벤트 리스너를 제거하려하지만 스크롤은 한 번만 작동 내 마우스 왼쪽 버튼을 발표 한 후, 전체 스크롤이 두 번째로 작동하지 않습니다.

그것은 (위 또는 아래) 사용자가 스크롤이에 걷어차하지 않고 버튼을 클릭 할 때 버튼 클릭 리스너를 무시 마우스 드래그처럼 어쩌면이 할 수 있습니까?

내 버튼 '클래스

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); 
      } 

    } 

내 홈페이지 (Spawner를) 클래스는

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(); 
    } 


} 

}

도움말을 이해할 수있을 것이다! 며칠 동안이 문제에 갇혀있었습니다.

UPDATE : 추가 된 새로운 업데이트 된 코드

안녕 얘들 아, 이제 내 문제는 내가 내 무비 클립을 스크롤 한 후, 코드가 scrollDiff에 대해 알아 듣는 것입니다 경우는 = 0

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; 
    } 


} 

} 

답변

1

이동 중에는 <container_mc>.mouseChildren = false을 움직입니다. 컨테이너 클립의 이동이 멈 추면 mouseChildren 속성을 'true'로 설정합니다. (나는 확실히 인생을 더 쉽게하기 위해, 구현 추천하는!) 크레이그의 대답에 추가

0

, 여기 당신이 계획대로이 작업을 할 수 매여 있어야 이벤트 리스너의 목록입니다. 이것은 이론이므로 조금만 둘러 봐야 할 수도 있습니다.

container.addEventListener(MouseEvent.MOUSE_DOWN, response);

: 당신은 마우스가 다운 플래그의 일종을 마련하고, 행동을 결정하는 다음 마우스 이벤트를 기다려야 할 것입니다.

container.addEventListener(MouseEvent.MOUSE_MOVE, response); : 마우스가 다운되면, 아이 클릭 (크레이그의 답변을) 해제와 드래그 시작합니다. 드래그 플래그를 올리고 싶을 수도 있습니다.

container.addEventListener(MouseEvent.MOUSE_UP, response); : 드래그 플래그가 발생하는 경우, 드래그를 중지하고 자식 클릭 수 있습니다. 올려지지 않은 경우 아무 것도하지 않으므로 항목이 거기에서 인계받을 수 있습니다.

item.addEventListener(MouseEvent.MOUSE_UP, itemResponse); : 클릭 동작.

MouseEvent를 사용하는 한 이론적으로 중첩 된 MovieClips에서 정상적으로 작동합니다.MOUSE_UP을 그것들의 리스너로서 사용합니다 (전술). MouseEvent.MOUSE_DOWN 또는 MouseEvent.CLICK를 사용하면 타이밍이 엉망이 될 수 있습니다. 그러나 나는 그 마지막 지점에서 잘못 될 수 있기 때문에 올바른 조합을 찾기 위해 약간의 실험을 할 것입니다.