2011-08-22 5 views
1

동적 텍스트 필드에서 일부 마우스 이벤트를 스크롤 텍스트에 넣으 려합니다.스크롤링하는 컨텐츠에 이벤트 수신기를 추가하려면 어떻게해야합니까?

예 : 여러 문장을 하나의 동적 텍스트 입력란에 입력합니다. 각 문장마다 다른 마우스 이벤트를 원합니다. 이와 같이 :

sentenceA.addEventListener(MouseEvent.CLICK, functionA); 

function functionA(evt:MouseEvent):void 
{ 
trace("bla"); 
} 

스크롤 텍스트의 각 문장에 eventlistener를 어떻게 추가 할 수 있습니까? 상대 텍스트 스크롤시 마우스 이벤트의 위치가 움직여야하기 때문입니다. 그런 경우가 아닌 경우

여기
+0

좋은 질문 !! – Eugeny89

답변

0

당신이 가서 ...

_txt.htmlText = "<a href='event:sentence1'>This is one sentenc.</a> <a href='event:sentence2'>This is another sentence.</a>" 
_txt.addEventListener(TextEvent.LINK, clickCopyHandler); 

function clickCopyHandler(e:TextEvent):void { 
    trace(e.text); 
} 
+0

대단히 감사합니다! 해봐! – nancy

0
 var sentences:Array = [ sentenceA, sentenceB, ...... ]; 

    function clickAllText(e:MouseEvent):void 
    { 
     var index:int; 
     for each(var s:String in sentences) 
     { 
      index = dynamicTextField.text.indexOf(s); 
      if(index >= 0 && index <= 3) 
      { 
       //if the sentence is in the front 
       this["sentence"+sentences.indexOf(s)](); 
       break;                               
      } 
     } 
    } 

    function sentence0():void 
    { 
    } 

    function sentence1():void 
    { 
    } 

, 당신은 문장 X에 마우스 포인트의 근접을 얻을 다른 텍스트 필드를 사용하거나 필요하거나 것 y 위치는 디스플레이에 표시됩니다.

0

href = '이벤트 : someText'속성을 가진 html 텍스트를 클릭하면 flash.event.TextEvent.LINK을 자세히 살펴보십시오. 다음 예제를 고려하십시오

var tf:TextField = new TextField(); 
tf.htmlText = "<a href='event:first'>sentence1.</a><a href='event:second'>sentence2.</a>"; 
tf.addEventListener("link", clickHandler); //link is value of flash.event.TextEvent.LINK 

function clickHandler(e:TextEvent):void { 
    //here should be something like the following 
    if (e.text == "first") sentence1(); 
    else if (e.text == "second") sentence2(); 
} 

글쎄, 당신이 생각을 잡았을 것 같아요! 문제는 문장을 태그에 넣을 수 있지만 링크를 일반 텍스트처럼 보이게 할 수 있다는 것입니다. 해당 변형이 귀하의 필요에 맞지 않으면 클릭 경계선 (tf.selectionBeginIndextf.selectionEndIndex)을 클릭 한 후 문장의 경계와 비교해보십시오.

관련 문제