02-13-2008, 06:29 PM
|
#1
|
|
|
Disabling textfield scrolling
Is there a way to disable scrolling on textfields? We are having a reoccuring problem where textfields that schouldn't be scrollable still scroll for 1 line.
You can see ALL of the text in a textfield (nothing is hidden below the fold), but when you click and drag, the text field scrolls up one line. This looks really sloppy but we can't find a fix. It seems that flash autosize makes the textfield a few pixels too short.
I've tried every variation I can and looked through the as docs with no luck. Any suggestions?
|
|
|
02-14-2008, 12:28 AM
|
#2
|
|
|
one suggestion is to try to reset scrollV property in an EventListener
Code:
myTextField.addEventListener(Event.SCROLL, onScroll);
function onScroll(evt:Event):void
{
myTextField.scrollV = 0;
}
Might look silly but would definitely work.
|
|
|
01-06-2009, 11:27 AM
|
#5
|

 |
Fredericton, NB, Canada |
|
 |
6 |
|
|
Quote:
Originally Posted by _moncton_
Is there a AS2.0 solution to that uses autosize
|
The answer was almost contained in the original question.
Quote:
Originally Posted by axiomflash
It seems that flash autosize makes the textfield a few pixels too short.
|
We just need to make the TextField a couple pixels taller than what the autoSize property allows.
It's still a little sloppy, but you can use autoSize to get your initial height, store that height, disable autoSize, then manually resize the TextField to your stored height (plus 2 pixels padding).
Code:
var tempHeight:Number;
myTextfield.autoSize = true;
tempHeight = myTextfield._height;
myTextfield.autoSize = false;
myTextfield._height = tempHeight + 2;
Alternatively, you could create a function that would autoSize any TextField on demand.
Code:
var sampleText:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Mauris eu massa a libero adipiscing rutrum.";
function autoSizeTF(tf:TextField):Void
{
var tempHeight:Number;
var padding:Number = 2;
tf.autoSize = true;
tempHeight = tf._height;
tf.autoSize = false;
tf._height = tempHeight + padding;
}
myTextField.text = sampleText;
autoSizeTF(myTextField);
Last edited by wmarcello; 01-06-2009 at 11:34 AM..
|
|
|
01-09-2009, 10:16 AM
|
#8
|
|
|
Hello, everybody!
Thanks for this thread!
I've found out that this issue also occurs when you use TextFormat.leading property, when formatting your text field.
Here is my code example:
Code:
var txtFld_txt:TextField = new TextField();
txtFld_txt.autoSize = TextFieldAutoSize.LEFT ;
txtFld_txt.multiline = true;
txtFld_txt.width = 120;
txtFld_txt.wordWrap = true;
txtFld_txt.text = "Halo! How are you? I'm fine, thanks! And you? I'm OKay. Have you managed to solve that textfield scroll problem?!";
txtFld_txt.border = true;
txtFld_txt.borderColor = 0x000000;
var txtFld_fmt:TextFormat = new TextFormat();
txtFld_fmt.leading = 7;
txtFld_txt.setTextFormat(txtFld_fmt);
As you can see, autosize and leading are used here - so the text field still can be scrolled.
Now if you comment txtFld_fmt.leading = 7; - everything will be great!
So probably the reason is that you have leading property set to a custom value...
|
|
|
01-09-2009, 01:02 PM
|
#10
|
|
|
Quote:
Originally Posted by axiomflash
Is there a way to disable scrolling on textfields?
|
Absolutely.
Code:
yourText.mouseWheelEnabled = false
I likes me a nice kludge.
|
|
|
11-13-2009, 07:18 AM
|
#12
|
|
|
I'm not sure that mine solution will help, but I use this:
textField.selectable = false;
textField.mouseWheelEnabled = false;
I don't need selectable text, so it won't scroll when you highlight it
__________________
I am not a miracle-worker, I am just learning...
|
|
|
12-26-2009, 07:55 PM
|
#13
|
|
|
Quote:
Originally Posted by Twinkle
I'm not sure that mine solution will help, but I use this:
textField.selectable = false;
textField.mouseWheelEnabled = false;
I don't need selectable text, so it won't scroll when you highlight it
|
Hehe, it's the 27 december... I'm really a stupid freak doing actionscript stuff this night.... Anyway I sorted out this problem and I'd like to share my solution.
1 first I add a custom textfield with some height
the first trouble is how many line the textfield is if this text is empty?
(i just add a recursive function for understand this) check at getMaxScroll.
2 second I extended the as2 solution above in an As3 dynamic way.
please tell me what do you think about.
Code:
package
{
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.events.Event;
import flash.events.TextEvent;
public class TextFieldUtil extends Sprite {
public function TextFieldUtil() { }
//undestand how many lines we can insert in a textField without scrolling
public static function getMaxScroll(t:TextField):int {
t.type = TextFieldType.INPUT;
var current_string:String = t.text;
t.text = "";
var l:int = 0;
var scrld:Boolean = false;
t.addEventListener(Event.SCROLL, checkScrl);
function checkScrl(e:Event) {
e.target.scrollV = 0;
t.text = current_string;
scrld = true;
}
while (scrld == false) {
l++
t.appendText("\n");
}
t.removeEventListener(Event.SCROLL, checkScrl);
return l;
}
public static function createCustomTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var t:TextField = new TextField();
t.type = TextFieldType.INPUT;
t.mouseWheelEnabled = false
t.wordWrap = true;
t.multiline = true;
t.x = x;
t.y = y;
t.width = width;
t.height = height;
//t.background = true;
//t.border = true;
var maxScroll:int = getMaxScroll(t);
t.addEventListener(Event.CHANGE, function (e:Event) { // lock text insertion and delete exceeding characters.
var t:TextField = e.target as TextField;
if (t.numLines > maxScroll) {
t.type = "dynamic";
}
while (t.numLines > maxScroll){
var current_string:String = t.text;
t.text = current_string.slice(0, -1);
}
t.type = "input";
});
return t;
}
}
}
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 04:33 PM.
|
|