Alert to auto-resize to fit the entire message without scrolling

660 views
Skip to first unread message

joy9977

unread,
Nov 7, 2008, 1:04:07 AM11/7/08
to Flex India Community
Hi
I have a situation, where I have a long texts in the alert-messages.
But this text is scrollable, and the alert-box is of fixed-size. What
I would like to have is:
1. The Alert-box should resize by itself to accomodate the whole alert-
msg ie. the whole msg should be visible without any scroling.
2. The alert-msg should not be scrollable.

I am using both the MX-Alert class, as well as my own custom alert-
class.

Please suggest a solution if possible.

Thanks in advance.

Vinod M. Jacob

unread,
Nov 7, 2008, 6:05:54 AM11/7/08
to flex_...@googlegroups.com
Try this:
 
 
<?xml version="1.0"?>
<!-- controls\alert\AlertSize.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;

            // Define variable to hold the Alert object.
            public var myAlert:Alert;

            private function openAlert():void {
                myAlert = Alert.show("Copy Text?", "Alert",
                    Alert.OK    | Alert.CANCEL);
                // Set the height and width of the Alert control.
                myAlert.height=150;
                myAlert.width=150;
            }
        ]]>
    </mx:Script>

        <mx:TextInput id="myInput"
            width="150"
            text=""/>
        <mx:Button id="myButton"
            label="Copy Text"
            click="openAlert();"/>
        <mx:TextInput id="myText"/>
</mx:Application>


joy9977

unread,
Nov 7, 2008, 7:27:02 AM11/7/08
to Flex India Community
Hi
What I need in this particular case is that, the alert's width and
height should adjust dynamically, depending on the amount of text in
the message. I dont want to hardcode the width/height to any value.
This is especially needed in the custom-alert class, where the amount
of text(alert-msg) can vary from few-words to even 50 lines.
Regards

Vinod M. Jacob

unread,
Nov 7, 2008, 7:45:16 AM11/7/08
to flex_...@googlegroups.com
Based on the length of the string you can set the width and height.I think thats is the only solution.

Venkat Viswanathan

unread,
Nov 9, 2008, 10:58:43 AM11/9/08
to flex_...@googlegroups.com
Hi,

Or probably write your own class using PopupManager and TitleWindow that will look like Alert but will have the auto-resize functionality as per your requirement.

Another way is to set the text to a TextField class and get the textWidth and textHeight property of the textField instance and set it to the Alert box. But this is more of a patchy way to achiving the results. You would get better results if you use the former idea.

Regards,
Venkat

veeru

unread,
May 18, 2012, 2:57:01 AM5/18/12
to flex_...@googlegroups.com
Just dont specify the width and height properties. It will take it automatically based on the Text lenght. If you are specifying any parent container for the alert box, then if the size of the parent element id not enough in that case it will over flow
Reply all
Reply to author
Forward
0 new messages