Cursor disappears when TextField.selectable = false; - actionscript-3

Cursor disappears when
TextField.selectable = false;
How can I make cursor to be visible but textfield not selectable(with mouse) or CTRL+A.

I've seen a similar problem in the past, but I don't remember how to duplicate it. It no longer appears in the project I first saw it in, so the two things which I know have happened since then are below. Of course, there could be some other variable, but the project is working now...
I suspect that the field is still editable. That would be my first guess. The first thing I would try then:
//( in a flash.text object ( Flash or Flex ) )
myTxtFld.type = TextFieldType.DYNAMIC;
//( in a mx.controls object ( Flex ) )
myTxtFld.editable = false;
If that does not work, try nesting the TextField in something with a MouseEvent.ROLL_OVER listener and useHandCursor set to False. eg:
var spt:Sprite = new Sprite();
spt.useHandCursor = false;
spt.addChild( myTxtFld );
spt.addEventListener( MouseEvent.ROLL_OVER, function( anon:* ){} );

I believe flash/as3 sees the text cursor as a zero width selection, I dont see how it should be possible to do what you want to here, except maybe extending textfield and placing your own cursor on mouseevents

Related

Actionscript: BlitMask stopping mouse event listeners from working, how to fix?

I have a button class which contains event listeners to trigger an animation of the button on click.
I used many instances of this class to form a list which the user can scroll through. I have implemented BlitMask, this works, however the mouse event listeners in the button class no longer work. This code
_blit = new BlitMask(_mc, _obounds.x, _bounds.y, _bounds.width, _bounds.height, false);
Is what stops the button class.
How can I get the behaviour pre blitmark?
My code which creates the bottom is
var tf:TextField = new TextField(text);
tf.x = 70;
tf.y = 20;
_btn.addChild(tf);
_btn.addEventListener(MouseEvent.CLICK, click);
click is never called.
The blitmask causes the movieclip to be nothing more than an image of clip.
bitmapMode must be set to false to correct this.
_blitMask.bitmapMode = false;
EDIT: To expand on a further issue that implementing this solution causes, turning bitmapMode on only when needed causes the bitmap to not reflect changes in the classes that changed while bitmapMode was off. So you must set
_blitMask.update(null, true);
To force a full update when you use
_blitMask.bitmapMode = true;

Blinking Caret Not Showing up in Input Text Field

I want one of my input text boxes to be the stage focus as well as have the blinking caret without the user needing to click inside the text field. I've been searching around frantically for an answer to this question, and everyone's answer boils down to this code: (the instance name of the text field being "input")
stage.focus = input;
input.setSelection(0, input.text.length);
But for some reason this code isn't working for me. Anyone have any idea why?
Update
For some reason this works:
stage.addEventListener(MouseEvent.CLICK,update);
function update(e:MouseEvent){
stage.focus = input;
}
And this does as well but the caret doesn't blink:
var counter:int=0;
stage.addEventListener(Event.ENTER_FRAME,update);
function update(e:Event){
counter++;
if(counter>30){
stage.focus = input;
}
}
This still doesn't satisfy my question though, why do you need a mouse click of some type in order to make my desired action work properly?
1.. How about if you set focus to happen inside a mouseClick function?
2.. Try this
stage.focus = input;
input.text = " "; //with a space (for blank but not empty);
input.setSelection(0, input.text.length);
3.. Bail out scenario then this utility might help or at least you'll learn something from its code Link here

Adobe Air 4.0 Mobile As3 - StageText restrict

we added a StageText object to our stage.
Everything works fine until we add the restriction:
myTextFieldName = new StageText();
myTextFieldName.editable = true;
myTextFieldName.autoCorrect = false;
myTextFieldName.stage = this.stage;
myTextFieldName.maxChars = 15;
myTextFieldName.fontSize = 35*SWF_HALF_WIDTH*2/620;
myTextFieldName.viewPort = new Rectangle(SWF_HALF_WIDTH-_nameIpSprite.width/2+255*SWF_HALF_WIDTH*2/620, _nameIpSprite.y+21*SWF_HALF_WIDTH*2/620,222*SWF_HALF_WIDTH*2/620,40*SWF_HALF_WIDTH*2/620);
myTextFieldName.text = "";
myTextFieldName.restrict = "0-9a-zA-Z";
myTextFieldName.returnKeyLabel = ReturnKeyLabel.GO;
The text gets restricted as we defined it but the big problem is that it inserts the characters that have already been typed in if you enter a new letter.
So I type in a "f" and after that an "m". It automatically adds an additional f so the result is "ffm" instead of "fm".
We also tried to add a change eventlistener:
myTextFieldName.addEventListener(Event.CHANGE, textFieldChangeEventHandler);
private function textFieldChangeEventHandler(event:Event):void
{
trace(event.target.text);
//Manage text
}
If we use that the cursor always went to the beginning of the string and every new letter is added at the beginning instead of the end...
Any experience with that?
Best
From what you saying i think it is a bug, i also found a bug in stage text related to RTL text and report it here,
i suggest to report this bug and use a code to restrict user input as workaround.

As3 text field issue

I'm trying to make a button(movieClip-button), that when you hover over it(MOUSE_OVER), it calls a function that displays some text. The only problem is that it doesn't work :p. Or atleast not the way i want it to work. The thing is when i hover over it the first time, nothing displays. If i then remove the mouse from the movieclip and hover over it again it works just fine. Here's my code:
private var priceString:TextField = new TextField();
private function addText(price:String):void{
var priceStringFormat = new TextFormat;
priceStringFormat.color = 0xFF0000;
priceStringFormat.font = 'TradeGothic';
priceStringFormat.size = 30;
priceString.x = 285;
priceString.y = 15;
priceString.setTextFormat(priceStringFormat);
priceString.autoSize = TextFieldAutoSize.LEFT;
priceString.text = "Upgrade Costs: " + price;
getStage.addChild(priceString);
}
I can't myself see the problem:s. Other text fields in the same format in the same class works just fine. The getStage var is holding the stage access. (It works with other text fields). Strange is also that if i try to add a movieclip instead of the textfield, it works just fine.
This is how it should look:
http://i.stack.imgur.com/5a0jf.png
setTextFormat needs to happen after you set the text property. If for whatever reason you need to do the formatting before you set the textFormat, use
priceString.defaultTextFormat = priceStringFormat
If you're saying you want to create a tooltip when you hover over a button, you should probably put the TextField into a Sprite object. Add the TextField as a child of the Sprite, and the Sprite as a child of the stage. Then, either tween the alpha value of the Sprite or toggle its visibility using Sprite.visible.
PS: for a detailed tutorial, see:
http://hub.tutsplus.com/tutorials/create-a-customizable-tooltip-in-actionscript-30--active-1793
EDIT:
Based on the image you provided, what you would need is to create a sprite with the TextField as its child in the constructor of your button, and set the sprite's visible property to false.
In your mouseover handler for the button, set the sprite's visible property to true, and in reset it in your mouseout handler.

Flex DRAG_DROP Event - Is it possible to access the Image Being Dragged?

When you start a Flex drag action, you pass in a proxy image to be displayed when you drag across the screen. When the drop occurs, I want to be able to grab this proxy but I can't find a way to from the DragEvent object.
Is it possible? What I want is to actually drop the dragged image when the mouse button is released... Flex automatically does a nice shrinking animation on the proxy but I don't want that.
The Flex examples show what I don't want - the proxy is removed and a new image added but not in exactly the right place...
More info: I tried adding my Proxy Image as a data item to the DragSource. I was able to access this when the drop occurred and saw there is a class mx.managers.dragClasses.DragProxy which seems to have all the info I need... but this class is not documented?
So there's two questions really... how to get the proxy and find out the position of the mouse cursor within the proxy, and how to disable the Flex drop animation.
The dragProxy is a static getter on the DragManager and is scoped to mx_internal. So to reference it, you'd have to do something like this:
import mx_internal;
And in a drag event handler:
var p:* = DragManager.mx_internal::dragProxy;
I'm not sure how you could prevent the animation. If I find out, I'll let you know.
For disabling the animation in the s:List, in a dragCompleteHandler override, you can 'hack' into the DragManager to get the dragProxy and hide it.
override protected function dragCompleteHandler(e:DragEvent):void
{
DragManager.mx_internal::dragProxy.visible = false; // <- MAGIC!
super.dragCompleteHandler(e);
}
Probably applicable in other situations.
Only way to prevent the animation:
-You have to monkey patch the DragProxy class (i.e. create a new class with identical name, code, and package structure), and remove the effects code from the mouseUpHandler().
No other way to override it as far as I know, though the issue was been submitted as a bug to Adobe over a year ago.
As far as getting the mouse coords for the proxy to drop it in the correct location try this:
assuming you are initiating the drag on mouseDown get the coords using e.currentTarget.contentMouseX and e.currentTarget.contentMouseY in your handler. then add these to the dragSource ( I did it as an object ) like:
var drgSrc:DragSource = new DragSource();
drgSrc.addData( { x:e.currentTarget.contentMouseX, y:e.currentTarget.contentMouseY }, 'drgXY' );
then in your drop handler ( assuming you are dropping it into a Canvas named drpCvs ):
var newImg:Image = new Image();
newImg.x = drpCvs.contentMouseX - e.dragSource.dataForFormat( 'drgXY' ).x;
newImg.y = drpCvs.contentMouseY - e.dragSource.dataForFormat( 'drgXY' ).y;
I found this while looking for a way to get rid of the shrink animation, so thanks for that. Thought I'd RTF.
If you just want to prevent the animation, the easiest (hackiest) way is this: create you're own proxy and add a MOUSE_UP handler to the stage that when triggered sets the visible property of your proxy to false. It won't actually stop the animation, it will just hide the proxy while the animation is happening. Something like this:
var proxy:UIComponent = new UIComponent();
proxy.graphics.lineStyle(1);
proxy.graphics.beginFill(0xccddff);
proxy.graphics.drawRect(0, 0, main.width, main.height);
stage.addEventListener(MouseEvent.MOUSE_UP, function (e:MouseEvent):void {
proxy.visible = false;
});
#ykessler: Thank you, the monkey patch worked like a charm. SDK: DragProxy.as
#Alvaro: I believe this approach results in a race condition. I tried it, and it only worked sometimes.
Setting
event.dragInitiator.visible = false;
in the drag drop handler works for me!
My solution to turn off the animation, was to set visible=0 onMouseUp in my custom ListItemDragProxy component.
My solution is to remove the MouseUp-Handler on SandboxRoot and attach an own MouseUp-Handler in dragEnterHandler of the target like this:
protected function dragEnterHandler(event:DragEvent):void{
DragManager.acceptDragDrop(this);
this.dragProxy = DragManager.mx_internal::dragProxy;// get drag proxy
var sm:ISystemManager = event.dragInitiator.systemManager.topLevelSystemManager as ISystemManager;
var ed:IEventDispatcher = sm.getSandboxRoot();
this.sandboxRoot = sm.getSandboxRoot();
//remove
ed.removeEventListener(MouseEvent.MOUSE_UP, dragProxy.mouseUpHandler, true);
//attach own
ed.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, true);
ed.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
this.dragInitiator = event.dragInitiator;}
In mouseUpHandler I've implemented the copy of function mouseUpHandler from original DragProxy.as and removed the Drop-Effect.