• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Multiline combobox with AS3?

Guide ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

Hi

Is there a way to define AS3 combobox to wrap long lines?

TOPICS
ActionScript

Views

7.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

if cb is your combobox, import the textinput class and use:

TextInput(cb.getChildAt(1)).textField.multiline=true
TextInput(cb.getChildAt(1)).textField.wordWrap=true

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

I tried to put those two line inside magLoaded function, but I got following error:

ReferenceError: Error #1065: Variable TextInput is not defined.

I use combobox component from library (CBtoc)... I populate it with following code, data comes from XML-file:

function magLoaded(e:Event) {
    CBtoc.prompt = magXML.tocHeader[currentMagId];

    CBtoc.visible = true;
    CBtoc.dropdown.rowHeight = 30;
     var tocNumero = CB.selectedIndex;
    var tocXML:XML;
    var tocLoader:URLLoader = new URLLoader();
    tocLoader.load(new URLRequest(magXML.Book.toc[tocNumero]));
    tocLoader.addEventListener(Event.COMPLETE, captureData2);

}

function captureData2(e:Event):void {
    CBtoc.removeAll();
    var tocXML:XML = new XML(e.target.data);
    var il:XMLList = tocXML.article;
   
    if (il.length()==1){
        CBtoc.visible = false;
        }
    for (var i:uint=0; i<il.length(); i++)
    {
        CBtoc.addItem({data:il.spread.text(),    label:il.name.text()});
       
    }
   
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

ok, I forgot to import textinput class, now it doesnt give me any warnings but combobox doesn´t wrap long lines either.... do I have those lines in wrong place?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

where's the code i suggested?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

I took it away before I pasted... sorry

It´s inside magLoaded fuction

function magLoaded(e:Event) {
    CBtoc.prompt = magXML.tocHeader[currentMagId];

    CBtoc.visible = true;
    CBtoc.dropdown.rowHeight = 30;

TextInput(CBtoc.getChildAt(1)).textField.multiline=true;
TextInput(CBtoc.getChildAt(1)).textField.wordWrap=true;


     var tocNumero = CB.selectedIndex;
    var tocXML:XML;
    var tocLoader:URLLoader = new URLLoader();
    tocLoader.load(new URLRequest(magXML.Book.toc[tocNumero]));
    tocLoader.addEventListener(Event.COMPLETE, captureData2);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

is that rowHeight sufficient to display 2 rows of text?  increase it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

it should be…

combo.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

double it and retest.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 08, 2010 Apr 08, 2010

Copy link to clipboard

Copied

didn´t work... actually I couldn´t use a value higher that 48.

With value 49 or higher, my drop-down menu turns to drop-up menu.... and because it´s on the top of the screen, opening list goes over the edge ...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

i don't think you have enough room to show the 2nd line.  take a screen shot after using this code:

function magLoaded(e:Event) {
    CBtoc.prompt =  magXML.tocHeader[currentMagId];

    CBtoc.visible = true;
     CBtoc.dropdown.rowHeight = 30;

TextInput(CBtoc.getChildAt(1)).textField.multiline=true;
TextInput(CBtoc.getChildAt(1)).textField.wordWrap=true;

TextInput(CBtoc.getChildAt(1)).textField.border=true;


      var tocNumero = CB.selectedIndex;
    var tocXML:XML;
    var  tocLoader:URLLoader = new URLLoader();
    tocLoader.load(new  URLRequest(magXML.Book.toc[tocNumero]));
     tocLoader.addEventListener(Event.COMPLETE, captureData2);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

border appeared around first line only:

cb2.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

there's no room for a 2nd line to display.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

can i make it bigger somehow? (it actually shows text in two lines if I make linebreak to xml where those labels are loaded)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

(it actually shows text in two lines if I make linebreak to xml where  those labels are loaded)

without increasing the row height?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

yep

cb3.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

and you're NOT using this code to achieve multiline support:

TextInput(CBtoc.getChildAt(1)).textField.multiline=true;
TextInput(CBtoc.getChildAt(1)).textField.wordWrap=true;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 09, 2010 Apr 09, 2010

Copy link to clipboard

Copied

Actually I was using that code when I took a screenshot, but it works also without... but my problem is that in real usage XML will be generated automatically without line breaks, so it´s not a solution...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2010 Apr 10, 2010

Copy link to clipboard

Copied

i don't understand what you're doing.

the combobox labels will not display multiline content unless you code for that.  there are a number of ways to do that and i gave one.  if you claim you're doing that another way, you haven't explained and if you're not doing anything to make your combobox multiline you're mis-reporting.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 10, 2010 Apr 10, 2010

Copy link to clipboard

Copied

Im loading labels from XML. I cant influence to that xml, it comes automatically from other system. Normally labels are quite short and they are always in one line without linebreaks in that xml. I can put some linebreaks to that xml manually for testing it, but thats not a solution for real system.

I´m trying to find a solution to put into that combobox. So that if label is more than, let´s say 30 characters, combobox would split that line into 2 or even 3 lines...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 10, 2010 Apr 10, 2010

Copy link to clipboard

Copied

Heres a simplified version of my project, I have stripped everything else off, just a combobox is left there, + of course XML that holds all those labels....

http://dl.dropbox.com/u/133381/cb_test.zip

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2010 Aug 03, 2010

Copy link to clipboard

Copied

The smaple provided as download does not work.

Can you please upload a revised sample.

Best

Harry

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 10, 2010 Aug 10, 2010

Copy link to clipboard

Copied

hmmm...strange, I just tried it and it worked for me... do you get some alert?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 10, 2012 Apr 10, 2012

Copy link to clipboard

Copied

You should use a custom CellRenderer like this:


=============================

import fl.controls.ComboBox;

ComboBox(dropDown).dropdown.setStyle("cellRenderer", MyCellRenderer);

=============================

Class MyCellRenderer
=============================

package views

{

    import flash.text.TextFormat;

    import fl.controls.listClasses.CellRenderer;

    public class MyCellRenderer extends CellRenderer

    {

        public function MyCellRenderer()

        {

            super();

        }

/*

/ This is another class of the CellRenderer class, which we need

/ to override to set new properties. We change the textField properties.

/ The textField is derived from the LabelButton, which is used for the

/ DataGrid and List components rows and headers. We set wordWrap to true if the

/ text is very long and give html properties to the textField. The string

/ for the textField has the name 'label'.

*/

        override protected function drawLayout():void

        {

            textField.wordWrap = true;

            textField.htmlText = this.label;

            super.drawLayout();

        }

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2012 May 09, 2012

Copy link to clipboard

Copied

I tried your solution. It works partially. The problem is that rowCount is fixed for all rows. Is there any solution for this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines