Wednesday, April 21, 2010

Prevent changing the cursur position in TextInput fields

Ever tried to prevent the user from changing the cursor position using the arrow keys (or other keys that normally change the cursor position)? In that case you probably already know that event.preventDefault() and event.stopImmediatePropagation() won't help you out. The code below seems to solve the problem:

private function keyDownHandler(event: KeyboardEvent): void
{
switch (event.keyCode)
{
case Keyboard.LEFT:
case Keyboard.RIGHT:
case Keyboard.UP:
case Keyboard.DOWN:
case Keyboard.PAGE_UP:
case Keyboard.PAGE_DOWN:
case Keyboard.HOME:
case Keyboard.END:
if (_orgSelectionBegin==-1) _orgSelectionBegin = selectionBeginIndex;
if (_orgSelectionEnd==-1) _orgSelectionEnd = selectionEndIndex;
setSelection(_orgSelectionBegin, _orgSelectionEnd);
break;
}
}

private function keyUpHandler(event: KeyboardEvent): void
{
_orgSelectionBegin = -1;
_orgSelectionEnd = -1;
}

private var _orgSelectionBegin: int = -1;
private var _orgSelectionEnd: int = -1;

Do you also think this is way too much code for doing something simple?
In that case vote for https://bugs.adobe.com/jira/browse/SDK-26279

Friday, February 26, 2010

Trouble accessing data from another server?

Of course you know about crossdomain.xml and you made sure that it's accessible. But you still get an error when you try to access data when doing an http request? If you're setting http headers through your Actionscript code then that is most probably the reason. Try specifying the "allow-http-request-from" attribute in your crossdomain.xml file.