Change combobox background color in AS3

by filip 8. November 2011 14:30

I needed to change the background color of the text region of a flash combobox - using AS3 at runtime.

Styles for some reason were not working.  The solution was to directly address the textfield property and change its background color.  Here's an example:

cbo.textField.textField.background = true;
cbo.textField.textField.backgroundColor = 0xDEDE29;

Tags: ,

Web Development

Flash Combobox setStyle works in Test (debug) and not in Publish (swf)

by filip 25. August 2011 12:15

I tried to customize the combobox ( AS3 ), and everything was working fine by using cbo.setStyle( "embedFonts" ) and cbo.setStyle( "textFormat" ) while testing the movie.  However, when I published the SWF, the styles were no longer working.

It seems like setStyle doesn't really work properly for comboboxes for some reason.  The solution was to apply the setStyle to the textField inside the combobox, and not to the combobox itself.

For example, this doesn't work: 

 

cbo.setStyle( "embedFonts", true );
cbo.setStyle( "textFormat", tf );

 

but this works:

cbo.textField.setStyle( "embedFonts", true );
cbo.textField.setStyle( "textFormat", tf );

 

Tags: , ,

Web Development

How To Make the ActionScript 3.0 (AS3) TextArea Not Selectable

by filip 18. September 2010 01:50

Here’s something I wasted like 45 minutes on, and it should be pretty trivial. I needed to make the TextArea component NOT selectable, yet still enabled (need the scrollbar to work).

I started digging around the TextArea.as class, because no matter what I did in my code (such as myTextArea.textField.selectable = false; ), the TextArea was still selectable. It appears that when the TextArea calls the draw() or setSize() methods, it updates the text field in the TextArea to be selectable depending on whether the TextArea is enabled or not.

Clearly, whoever designed the TextArea component didn’t give this much thought. In any case, the way I got around the issue is to attach to the Event.Render event of the text area. Therefore, after the render method is called (and the TextArea is drawn), I can update the textfield to not be selectable.  Here is some sample code.You may need to attach to more events than just the render event, but the concept should work.

var DescriptionField:TextArea = getChildByName( "description" ) as TextArea;
DescriptionField.addEventListener( Event.RENDER, onDescriptionRender );

public function onDescriptionRender( evt:Event ):void
{
     var textArea:TextArea = evt.target as TextArea;
     textArea.textField.selectable = false;       
}

Tags: , ,

Web Development

About Filip Stanek

Death Note Pic I'm a developer at ACG in Cincinnati, OH. I like ASP.NET, Flash, and other web technologies, & enjoy playing chess, video games, etc.

Currently playing:

Disqus

Month List