Go Back   kirupaForum > Flash > ActionScript 3.0

Reply
 
Thread Tools Display Modes
Old 02-13-2008, 06:29 PM   #1
axiomflash
Registered User
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?
axiomflash is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 02-14-2008, 12:28 AM   #2
bzouchir
Registered User
Location Sydney, Australia

Posts 144
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.
bzouchir is offline   Reply With Quote
Old 10-23-2008, 04:22 PM   #3
dustinscherer
Registered User
Location Rosharon, Texas, U.S.A.

Posts 7
I know this is a very old post, but in case anyone runs across this issue as I just did, another fix you can do is to not set the height using the autosize, but instead use the .height property set manually. Like this:

It renders a slightly better result as the text field doesn't jump around when you try to select.

Code:
///enough text to make a paragraph
var t:String="asdfsdf asd fasd asd fdasf f eaafw es asf as efaes afs efas afes afe af ";
t += "faef as asefsdfsdf asd fasd asd fdasf f eaafw es asf as efaes afs efas afes afe af";
t += "asefsdfsdf asd fasd asd fdasf ewa f es asf as efaes afs efas afes afe af faef as";
t += "asefsdfsdf asd fasd asd fdasf ewa f es asf as efaes afs efas afes afe af faef as";

//tf.autoSize=TextFieldAutoSize.LEFT;
tf.text=t;
var h_buffer:Number = new Number(6);
tf.height = tf.textHeight+h_buffer;

__________________
What was Adobe's first though when they bought Macromedia Flash, "Let's make it better?" or "Let's start over?"

MouseEvent.MOUSE_OVER > on mouseEnter me
dustinscherer is offline   Reply With Quote
Old 01-06-2009, 10:20 AM   #4
_moncton_
Registered User
Is there a AS2.0 solution to that uses autosize
_moncton_ is offline   Reply With Quote
Old 01-06-2009, 11:27 AM   #5
wmarcello
Registered User
Location Fredericton, NB, Canada

Posts 6
Quote:
Originally Posted by _moncton_ View Post
Is there a AS2.0 solution to that uses autosize
The answer was almost contained in the original question.

Quote:
Originally Posted by axiomflash View Post
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..
wmarcello is offline   Reply With Quote
Old 01-06-2009, 11:44 AM   #6
cesig
Senior Flash Monkey
 
cesig's Avatar
Well, since this post was resurrected, I'll try to add to it for people in the future with this issue.

We had this issue on a project at work, and we made a utility for it that pastes the content in, checks the height of the text (from the autosize), and then sets the height of the TextField to that value.

I think the reason you're seeing this issue is because the line height is larger than 1. I believe that's why this happens. So, on the single-line text field set the line height to <=1 and it should stop scrolling.
cesig is offline   Reply With Quote
Old 01-06-2009, 02:06 PM   #7
mr.skribbs
Registered User
You could do a quick fix by setting the text height with an offset:

textfield._height= textfield.textHeight + 10;
mr.skribbs is offline   Reply With Quote
Old 01-09-2009, 10:16 AM   #8
ttu
Registered User
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...

__________________
Coke, popcorn ‘n’ Flash
ttu is offline   Reply With Quote
Old 01-09-2009, 12:33 PM   #9
cesig
Senior Flash Monkey
 
cesig's Avatar
Crap. I meant leading in my other post.
cesig is offline   Reply With Quote
Old 01-09-2009, 01:02 PM   #10
efos
Registered User
Quote:
Originally Posted by axiomflash View Post
Is there a way to disable scrolling on textfields?
Absolutely.

Code:
yourText.mouseWheelEnabled = false
I likes me a nice kludge.
efos is offline   Reply With Quote
Old 01-09-2009, 01:04 PM   #11
cesig
Senior Flash Monkey
 
cesig's Avatar
efos:
Unfortunately, that doesn't prevent the text from scrolling if you highlight it with the mouse.
cesig is offline   Reply With Quote
Old 11-13-2009, 07:18 AM   #12
Twinkle
Registered User
 
Twinkle's Avatar
Location Ukraine, Odessa

Posts 2
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...
Twinkle is offline   Reply With Quote
Old 12-26-2009, 07:55 PM   #13
boxbuilder
Registered User
Afrostyle

Quote:
Originally Posted by Twinkle View Post
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;
        }
    }
}
boxbuilder is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:33 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com