Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Input Text and Sprite Dragging

Community Expert ,
Apr 07, 2009 Apr 07, 2009

I'm trying to create a draggable dialog, which includes an input text field and I want to prevent the dialog from dragging when the input text is selected. If I create a sprite with a hit area at the top everything works as expected, but when I add the input text field below the hit area selecting the text drags the dialog. Here's an example of the problem:

import flash.display.Sprite;

import flash.events.MouseEvent;

import flash.text.TextField;

import flash.text.TextFormat;

//dialog back

var rectshape:Sprite= new Sprite();

rectshape.graphics.beginFill(0xCCDDCC,.8);

rectshape.graphics.drawRect(0,0,400,300);

rectshape.graphics.endFill();

addChild(rectshape);

rectshape.buttonMode=true;

rectshape.addEventListener(MouseEvent.MOUSE_DOWN, onClick);

stage.addEventListener(MouseEvent.MOUSE_UP, onUp);

//hit area

var hit:Sprite= new Sprite();

hit.graphics.beginFill(0,.2);

hit.graphics.drawRect(0,0,400,40);

hit.graphics.endFill();

rectshape.addChild(hit);

//define the hit area

rectshape.hitArea=hit;

rectshape.x=200;

rectshape.y=200;

//input text

var format:TextFormat=new TextFormat();

var tf:TextField=new TextField();

rectshape.addChild(tf);

tf.x=20;

tf.y=50;

tf.width=350;

tf.height=150;

format.size=17;

format.color=0xFFFFFF;

format.align="left";

tf.multiline=true;

tf.wordWrap=true;

tf.selectable=true;

tf.defaultTextFormat=format;

tf.text="input text--Na alit et la cor susciduip enim dolenim acil ut prat nis nulputat ipit velissenit lamet, consed tionullam, quat. Equatum dunt praessit dignismodip et lortin ent acilla faci tat nonsed mod elestrud tem vel dit veliquis non hendiam, volore facidunt ipisl ullaore dit alit dionsed modipis nonsecte modion henissi.";

function onClick(event:MouseEvent):void {

rectshape.startDrag(false);

}

function onUp(event:MouseEvent):void {

rectshape.stopDrag();

}

TOPICS
ActionScript
809
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 07, 2009 Apr 07, 2009

i don't see where you made your textfield's type "input", but to answer your question just add a MOUSE_DOWN listener to your textfield and enable the use-capture phase of your rectshape:

rectshape.addEventListener(MouseEvent.MOUSE_DOWN,onClick,true);

tf.addEventListener(MouseEvent.MOUSE_DOWN,whateverF);

Translate
Community Expert ,
Apr 07, 2009 Apr 07, 2009

i don't see where you made your textfield's type "input", but to answer your question just add a MOUSE_DOWN listener to your textfield and enable the use-capture phase of your rectshape:

rectshape.addEventListener(MouseEvent.MOUSE_DOWN,onClick,true);

tf.addEventListener(MouseEvent.MOUSE_DOWN,whateverF);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2009 Apr 07, 2009

Thanks. I've always been phase-challenged.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2009 Apr 07, 2009
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines