views:

13

answers:

1

I'm using Flash CS4. Everything functions as it should when CS4 previews the swf after compiling it.

However, after embedding the flash item in a webpage, if the textArea loses focus within the flash piece, the textarea's built-in UIscrollbar resets to the very top.

Here's the kicker: if I add a FOCUS_OUT event listener to the textArea to store the current scrollbar value, I find that the scrollbar value has been reset to minimum even before the FOCUS_OUT event is triggered! WTF?

I think this is occurring because the textArea's htmlText propery is dynamically populated. Adobe AIR has advanced methods for handing HTML, but not simple AS3, oh no. How obnoxious. What can be done?

A: 

I never thought I'd answer my own question, but here it is. Turns out the htmlText thing may have been a canard. The scrollbar jitter happens in between the dynamically generated content window's being clicked and its losing focus, so this captures the current position and whether the scrollbar's at the bottom on the click event and passes that info to the focus event. displayWindow is the one with dynamically generated content.

I am relatively new to AS3, so let me know if any of this isn't kosher.

displayWindow.addEventListener(MouseEvent.ROLL_OUT, handleClick);
function handleClick(event:MouseEvent):void
{
    //here, user has clicked output window
    var currentPosition = displayWindow.verticalScrollPosition;
    var atTheBottom:Boolean = (currentPosition == displayWindow.maxVerticalScrollPosition);
   var focusAdded:Boolean = false;
   displayWindow.addEventListener(FocusEvent.FOCUS_OUT, 
   function handy() {
        //here, user has clicked away from output window  

       if (!focusAdded) {
            if (atTheBottom)
                displayWindow.verticalScrollPosition = displayWindow.maxVerticalScrollPosition;
            else
                displayWindow.verticalScrollPosition = currentPosition;

            focusAdded = true;

        } else {
            displayWindow.removeEventListener(FocusEvent.FOCUS_OUT, handy);
            focusAdded = false;
        }
    }
   );
}
Rujiel