动态地更改文本与拖/放在Flash CS6(AS3) [英] Changing text dynamically with drag / drop in Flash CS6 (AS3)

查看:364
本文介绍了动态地更改文本与拖/放在Flash CS6(AS3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些非常简单code,它工作正常,在让我水平拖动一个滚动条按钮。不过,我也想显示的对象的上面,这取决于什么样的x坐标是我拖动对象的更改文本。

I have some incredibly simple code that works fine in letting me drag a "slider" button horizontally. However, I also want the text that appears above the object to change depending upon what the x-coordinate is of the object I'm dragging.

下面是简单的code:

Here's the simple code:

var rectangle:Rectangle = new Rectangle(31,944,179,0);
Button.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

function fl_ClickToDrag(event:MouseEvent):void
   {
    Button.startDrag(false, rectangle);
   }

Button.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
   {
    Button.stopDrag();
    gotoAndPlay(20);
}

什么我想要做的是使系统确定的按钮是在以下方面其x坐标,而如果x坐标是高于,比方说,50,在上述的按钮的文本说50+,并且如果x坐标是高于100的文本改变为100+。我也不知道,如果x坐标应该是相对于矩形或相对于整个屏幕。

What I'm wanting to do is have the system determine where the "Button" is in terms of its x-coordinate, and if the x-coordinate is higher than, say, 50, for the text above the "Button" to say "50+", and if the x-coordinate is higher than 100 for the text to change to "100+". I'm also not sure if the x-coordinate should be relative to the rectangle or relative to the entire screen.

任何及所有的帮助是AP preciated。

Any and all help is appreciated.

推荐答案

您可以使用一个布尔值VAR来表示,如果拖动你的按钮,如果,然后更新您的文本字段是这样的:

You can use a boolean var to indicate if your button is dragged and if, then update your text field like this :

var is_dragged:Boolean = false;
var rectangle:Rectangle = new Rectangle(0, 100, stage.stageWidth - button.width, 0);

stage.addEventListener(Event.ENTER_FRAME, _onEnterFrame);
function _onEnterFrame(e:Event):void {
    if(is_dragged){
        text_field.text = String(Math.round(button.x / 50) * 50) + '+';
    }
}

button.addEventListener(MouseEvent.MOUSE_DOWN, button_onPress);
function button_onPress(e:MouseEvent):void {    
    button.startDrag(false, rectangle);
    is_dragged = true;
}

button.addEventListener(MouseEvent.MOUSE_UP, button_onRelease);
function button_onRelease(e:MouseEvent):void {
    button.stopDrag();
    is_dragged = false;
}

您可以看到这个code工作这里

You can see this code working here.

希望能有所帮助。

这篇关于动态地更改文本与拖/放在Flash CS6(AS3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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