闪光CS5的startDrag只能够从一个特定点拖动对象 [英] Flash CS5 startDrag only able to drag an object from a specific point

查看:165
本文介绍了闪光CS5的startDrag只能够从一个特定点拖动对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个当你点击我的当前游戏内的暂停按钮添加一个暂停屏幕。一旦被调用,在PausePanel类踢,并增加了观点,以自己的舞台(这是一个单一的影片剪辑称为PauseScreenView包含所有按钮,滑动条,等我需要它来的)。在此暂停面板中,我试图建立一个自定义的滑块,所以我可以控制音量。现在,我忽略了整体成交量的事情,只是想获得它,以显示在动态文本窗口相同的暂停面板上的一些文字。现在我拥有了一切设置和工作,但是,有一个问题。我只能抢滑块旋钮(称为volKnob),当它是在它的范围内的远端。而为了让事情变得更糟,我不能从旋钮影片剪辑的图形,除了左边缘的任意位置时,它在其范围内的左侧和右侧边缘时,它的右侧的范围内抓住它。另外,如果我放开它,而不是在远边的话,我不能再抓住它。我已经设置了其他拖动前,一个甚至在本场比赛的另一个地方。他们都做工精细,我可以抓住物体从任何地方我想要的图形的边缘内。不过,此页面上,我似乎无法得到它除了边缘。现在,这是我第一次尝试设置一个限制它的范围,但如果我把该位出它仍然不会让我从刚才的任何地方抓住它。这里是PausePanel.as code:

I have a pause screen that is being added when you click the pause button inside my current game. Once this is called, the PausePanel class kicks in and adds a 'view' to itself to the stage (which is a single movie clip called PauseScreenView that contains all of the buttons, sliders, etc. that I need it to). In this pause panel, I'm trying to set up a custom slider so I can control the volume. Right now I'm ignoring the whole volume thing and just trying to get it to display some text in a dynamic text window on the same pause panel. Now I have everything set up and working, however, there is a problem. I can only "grab" the slider knob (called volKnob) when it is at the far ends of it's range. And to make things worse, I can't grab it from anywhere on the knob movieclip graphic except the left edge when it's on the left side of its range and the right edge when it's on the right side of its range. Also if I let go of it while not at a far edge, then I can't grab it again at all. I've set up other drags before, and one is even in another place of this game. They all work fine and I can grab the object from anywhere I want within the edges of the graphic. But on this page I can't seem to get it except for the edges. Now this is the first time I have tried setting a limit to it's range, but if I take that bit out it still won't let me grab it from just anywhere. Here is the PausePanel.as code:

package {
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.geom.Rectangle;

public class PausePanel extends MovieClip {
    public var viewPause:PauseScreenView;

    private var boundsRect:Rectangle;

    public function PausePanel():void {
        addEventListener(Event.ADDED_TO_STAGE, addedToStage);
    }

    private function addedToStage(e:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE, addedToStage);

        //add the graphics
        viewPause = addChild(new PauseScreenView()) as PauseScreenView;

        //set up variables
        boundsRect = new Rectangle(60, 185, 360, 0);

        addEventListener(Event.ENTER_FRAME, onEnterFrame);

        viewPause.Knob.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
    }

    private function onEnterFrame(event:Event):void {
        sliderValue = viewPause.Knob.x / 3;
        viewPause.status_txt.text = "Slider position is: " + sliderValue;
    }

    private function startDragging(event:MouseEvent):void {
        var currentDragObject:MovieClip = event.currentTarget as MovieClip;
        currentDragObject.startDrag(true, boundsRect);
            currentDragObject.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
    }

    private function stopDragging(event:MouseEvent):void {
        var currentDragObject:MovieClip = event.currentTarget as MovieClip;
         currentDragObject.stopDrag();
        currentDragObject.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);
    }
}

}

有一些人看到的,我错过了一些东西,或者设置一些不正确?我已经尝试了一些不同的东西,所有的人都在同一个搞砸的方式工作。任何想法?

Is there something that anyone see's where I missed something or set up something incorrectly? I have tried a number of different things and all of them have worked in the same messed up way. Any ideas?

更新:

好,我把这个code出来,并使其构造类的空白FLA只是一个按钮和文本窗口。有一次我拿出这个viewPause部分,它完美的作品。它伤就像你想的那样。这个问题应运而生的事实,旋钮是viewPause的孩子似乎?有一些特殊的技巧,以获得一拖工作的时候拖动对象是另一个类的子对象我除了显示如何在code(即viewPause.Knob)??

OK I took this code out and made it the constructor class for a blank fla with just a knob and text window. Once I took out the viewPause section of this, it works perfectly. It drags just like you think it would. The problem comes into being with the fact that the knob is a child of viewPause it seems? Is there some special trick to getting a drag to work when the drag object is a sub-object of another besides how I show it in the code (i.e. viewPause.Knob)??

推荐答案

这code其实完全适用于任何恰好搜索这个话题谁。我的问题是存在的,因为我有一个范围设置鼠标不工作,所以虚假点击也不会在屏幕下面是这一个上发生。该范围恰好是在大多数我创建只是在滑块范围边缘的滑块对象的顶部。因此,我的问题。那么到底它是导致此不正常只是程序设计师的错误。

This code actually works perfectly for anyone who happens to search this topic. My problem was occurring because I had a range set up that the mouse would not work so false clicks wouldn't occur on the screen that is below this one. The range just happened to be over top of the majority of this slider object I was creating except at the edges of the sliders range. Hence my problem. So in the end it was just programer error that caused this not to function properly.

这篇关于闪光CS5的startDrag只能够从一个特定点拖动对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆