Skip to content Skip to sidebar Skip to footer

Actionscript 3: Maintaining Textarea Uiscrollbar Position On Loss Of Focus In Flash Embed

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 foc

Solution 1:

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);
functionhandleClick(event:MouseEvent):void
{
    //here, user has clicked output windowvar currentPosition = displayWindow.verticalScrollPosition;
    varatTheBottom:Boolean = (currentPosition == displayWindow.maxVerticalScrollPosition);
   varfocusAdded:Boolean = false;
   displayWindow.addEventListener(FocusEvent.FOCUS_OUT, 
   functionhandy() {
        //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;
        }
    }
   );
}

Post a Comment for "Actionscript 3: Maintaining Textarea Uiscrollbar Position On Loss Of Focus In Flash Embed"