2 Replies Latest reply on Oct 10, 2011 2:53 PM by stubbs311

    Flex 4 Adobe "workaround" in LinkElement.as line 681 crashing

    MotionMaker Level 1

      I am getting this error from Adobe LinkElement code where the documentation has notes about a workaround due to fast mouse movement.

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at  flashx.textLayout.elements::LinkElement$/stageMouseMoveHandler()[C:\Vellum\branches\v1\1. 1\dev\output\openSource\textLayout\src\flashx\textLayout\elements\LinkElement.as:681]

      The error occurs when the RichEditableText textFlow property is updated via binding from the model a second time. Moving the mouse around causes the error.

      I am listening for FlowElementMouseEvent.CLICK on HTML link elements.

      <?xml version="1.0" encoding="utf-8"?>
      <s:Panel
           xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:sf="http://www.spicefactory.org/parsley"
           title = "{model.term}"
           >
           <fx:Declarations>
               <!--
               Parsely will manage this component.
               -->
               <sf:Configure/>
           </fx:Declarations>
           <fx:Script>
               <![CDATA[
                   import com.alh.defineit.events.TermEvent;
                   import com.alh.defineit.model.TermModel;
                   import com.alh.defineit.services.ITermService;
                  
                   import flashx.textLayout.conversion.TextConverter;
                   import flashx.textLayout.elements.LinkElement;
                   import flashx.textLayout.elements.TextFlow;
                   import flashx.textLayout.events.FlowElementMouseEvent;
                   import flashx.textLayout.events.UpdateCompleteEvent;
                  
                   import mx.events.FlexEvent;
                  
                   import spark.events.TextOperationEvent;
                   import spark.utils.TextFlowUtil;
                   /**
                    * Inject the model.
                    * The [Inject] metadata searches context for an object of matching type.
                    */
                   [Inject]
                   [Bindable]
                   public var model:TermModel;
                   [Inject]
                   public var service:ITermService;
                           
                   protected function mouseClickHandler( event:FlowElementMouseEvent ):void
                   {
                       trace("mouseClickHandler");
                       event.stopImmediatePropagation();
                       event.preventDefault();
                       var href:String = LinkElement(event.flowElement).href;
                       trace(href);
                       var hrefParts:Array = href.split("getTerm(");
                       if (hrefParts.length ==2)
                       {
                           hrefParts = hrefParts[1].split(")");
                           if (hrefParts.length == 2)
                           {

       

                               var termNumber:uint = uint(hrefParts[0] );
                               service.getTermByTermNumber(termNumber);
                              
                           }
                       }
                      
                   }
                   protected function termDescription_rt_valueCommitHandler(event:FlexEvent):void
                   {
                       trace("termDescription_rt_valueCommitHandler");
                       termDescription_rt.textFlow.addEventListener(FlowElementMouseEvent.CLICK, mouseClickHandler );

       

                   }



               ]]>
           </fx:Script>
           <!--
           UI
           -->
           <s:layout>
               <s:VerticalLayout gap="10" paddingLeft="12" paddingRight="12" paddingBottom="12" paddingTop="12"/>
           </s:layout>
           <s:HGroup verticalAlign="middle">
               <!--<s:TextArea -->
                   <s:RichEditableText
                   id = "termDescription_rt"
                   width="500" height="100%"
                   valueCommit="termDescription_rt_valueCommitHandler(event)" 
                   selectable="false"
                   editable="false"
                   textFlow="{TextConverter.importToFlow( model.description, TextConverter.TEXT_FIELD_HTML_FORMAT )}"
                   />

       

           </s:HGroup>
           <!--
           Filler
           -->
           <s:Rect height="100%"/>

       

           <s:Label text="{'Total Terms: ' +  model.applicationModel.totalTerms }"/>
      </s:Panel>
        • 1. Re: Flex 4 Adobe "workaround" in LinkElement.as line 681 crashing
          MotionMaker Level 1

          Here is the comment in the Adobe code.

           

                  /** @private */
                  // This function is a workaround for Flash Player bug in Astro where mouseOut event is not sent from eventMirror if mouse
                  // has left the TextLine at the next sample point (i.e., mouse leaves TextLine rapidly).
                  private static function stageMouseMoveHandler(evt:MouseEvent):void
                  {

           

          and this is the line failing.

           

                              if (mirrorRegions)
                              {
                                  for (var i:int = 0; i < mirrorRegions.length; i++)
                                  {
                                     if (_mouseInLinkElement.groupElement == (mirrorRegions[i].element as GroupElement))
                                          found = true;
                                  }
                              }

           

           

          The error does seem to appear when the mouse is moved into the spark RichEditableText. Speed is not a factor as the note implies. Same error occurs if you have spark TextArea

           

           

          My coding goal was to call internal function (remember the asfunction days) on hyperlinks. That seems to work but the movement of the mouse fouls it up.

           

           

          UPDATE: This thread seems to have related information.

          • 2. Re: Flex 4 Adobe "workaround" in LinkElement.as line 681 crashing
            stubbs311

            I had this same issue adding a tool tip on roll over and out fixed it. I think it was a race condtion. Here is my roll over and out function.

            private function

                      handler_entryTextFlow_rollOver(event:FlowElementMouseEvent):void

                                          {

                                                    if(linkToolTip)

                                                    {

                                                              ToolTipManager.destroyToolTip(linkToolTip);

                                                              linkToolTip = null;

                                                    }

             

                                                    if(event.flowElement is LinkElement)

                                                    {

                                                              var link:LinkElement = event.flowElement as LinkElement;

             

                                                              var href:String = link.href.replace('event:','');

                                                              var name:String = href.substring(0,href.search('='));

                                                              var value:String = href.substring(href.search('=')+1,href.length);

             

                                                              var tipLabel:String = 'Visit this link.';

             

                                                              var p:Point = localToGlobal(new Point(mouseX+4,mouseY+16));

                                                              linkToolTip = ToolTipManager.createToolTip(tipLabel,Math.min(stage.width-200,p.x),Math.min(stage.height -48,p.y));

             

                                                    }

                                          }

             

                                          private function handler_entryTextFlow_rollOut(event:FlowElementMouseEvent):void

                                          {

                                                    if(linkToolTip)

                                                    {

                                                              ToolTipManager.destroyToolTip(linkToolTip);

                                                              linkToolTip = null;

                                                    }

                                          }