2 Replies Latest reply on Nov 26, 2012 12:46 AM by Da嗒_Sunny

    Click attribute in textFlow anchor tag in Flash Builder 4

    bornaeon Level 1

      Hi folks,

      At first congratulation to you, Adobe and Flex team for Adobe Flash Builder 4 & flex 4 SDK final release...

      then, I have a click attribute in my textFlow anchor tag, just like this:

       

      <fx:Script>
           <![CDATA[
       
           import mx.controls.Alert;
       
           public function func():void{
                Alert.show("hello!");
           }
       
           ]]>
      </fx:Script>
       
      <s:RichEditableText x="50" y="50" editable="false" id="RET" >
           <s:TextFlow>
                <s:a href='http://www.adobe.com' click='func()'>
                     <s:img source='adobe.jpg' width='50' height='50' />
                </s:a>
           </s:TextFlow>
      </s:RichEditableText>
      

       

      When I run the project, everything's allright; and after click on my image, I have adobe site in new window, and also have my popup alert window with "Hello!" text...

      But the Problem is another thing. I want to give this textFlow content from one webservice and put it in a string var then bind it to my RichEditableText. I receive it from webservice, put it in the string, and then bind this string to textFlow attribute of my RichEditableText obj with simple function... after running my project, I can see the content, and when I click on my image, I have adobe site in new window, again. but my function does not call!

      What is the problem?! the code is something like this (of course without webservice codes!):

       

      <fx:Script>
           <![CDATA[
       
           import flashx.textLayout.conversion.TextConverter;
           import mx.controls.Alert;
       
           public function func():void{
                Alert.show("hello!");
           }
       
           internal var str:String;
           public function func2():void{
                str = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008' paddingRight='5'>"+
                "<a href='http://www.adobe.com' click='func();'><img source='adobe.jpg' width='50' height='50' /></a>"+
                "</TextFlow>";
                RET.textFlow= TextConverter.importToFlow(str, TextConverter.TEXT_LAYOUT_FORMAT);
           }
       
           ]]>
       
      </fx:Script>
       
      <s:RichEditableText x="50" y="50" editable="false" id="RET" />
      

        • 1. Re: Click attribute in textFlow anchor tag in Flash Builder 4
          injpix Level 3

          Listening for a FlowElementMouseEvent.CLICK event will be beneficial.

           

          In your webservice feed (Textflow), have a tag such as:

          <a href="event:adobe.jpg">Click here to view Adobe's logo!</a>
          

           

          Then in your ActionScript code, listen for any FlowElementMouseEvent.CLICK events from your textFlow instance.

          textFlow.addEventListener(FlowElementMouseEvent.CLICK,
           onLinkHandler);
          

           

          Next, declare onLinkHandler:

                    /**
                     * In the XML there are href tag which has 'event:' prefix to the value.  This prefix
                     * allows method calls.
                     */
                    private function onLinkHandler(event:FlowElementMouseEvent):void
                    {
                         //extract the number value from the string.
                         var uri:String = LinkElement(event.flowElement).href.split(":")[1];
                         
                         trace(uri);//outputs: adobe.jpg
                    }
          
          • 2. Re: Click attribute in textFlow anchor tag in Flash Builder 4
            Da嗒_Sunny

            Looks very well, but it works not well.