Ok,
I solve it handling the icon in the parent class:
public function ButtonPanelClass():void {
addEventListener(FlexEvent.CREATION_COMPLETE,
creationCompleteHandler);
}
private function creationCompleteHandler(event:FlexEvent):void {
nuevo_btn.setStyle("icon", EmbeddedAssets.nuevo_icono);
}
Hope this help someone trying the same
Thanks
C.
On 2/6/07, Carlos Rovira <[EMAIL PROTECTED]> wrote:
Hi Tracy,
Thanks for the response. Please could you write a one or lines showing
what you are explaing?
Thanks!
C.
On 2/6/07, Tracy Spratt <[EMAIL PROTECTED]> wrote:
>
> Pass a reference to the subclass {this} into the base class, and use
> it to refer to subclass items. That sets up dependencies and typing issues
> you should be aware of though. Probably an event mechanism would be better.
>
>
>
> Tracy
>
>
> ------------------------------
>
> *From:* [EMAIL PROTECTED] ups.com [mailto:[EMAIL PROTECTED] ups.com]
> *On Behalf Of *Carlos Rovira
> *Sent:* Tuesday, February 06, 2007 4:37 PM
> *To:* flexcoders@yahoogroups.com
> *Subject:* [flexcoders] How to assign an icon using code behind? (Maybe
> a flex compiler bug)
>
>
>
> Hi,
>
> I'm trying to use code behind technique and have a compiler problem. I
> 'm trying to set an icon in a Button control, but the compiler not allow me
> to do this. The following are the classes use to show you the problem
>
>
> The following is the parent class:
>
> ButtonPanelClass.as
> ===============
>
> package components {
>
> import mx.containers.HBox;
> import mx.controls.Button;
> import assets.EmbeddedAssets ;
>
> public class ButtonPanelClass extends HBox {
>
> public var new_btn:Button;
> }
> }
>
> Next is the mxml that extends the parent class:
>
> ButtonPanel.mxml
> =============
>
> <?xml version="1.0" encoding="utf-8"?>
> <comps:ButtonPanelClass
> xmlns:comps="components.*"
> xmlns:mx="http://www.adobe.com/2006/mxml "
> >
>
> <mx:Button id="new_btn" label="New" icon="{EmbeddedAssets.new_icono
> }"/>
>
> <mx:Script>
> <![CDATA[
> import assets.EmbeddedAssets;
> ]]>
> </mx:Script>
>
> </comps:ButtonPanelClass>
>
> Now the assets class I'm trying to use with an icon:
>
> EmbeddedAssets.as
> ===============
>
> package assets {
>
> public class EmbeddedAssets {
>
> [Embed(source="/assets/icons/16/new_icon.png")]
> public static const new_icono:Class;
> }
> }
>
>
> Now you have to use the following tag in your mx:Application and set the
> namespace of course (xmlns:comps="components.*")
>
>
> <comps:ButtonPanel/>
>
>
> This is the result:
>
> Severity and Description Path Resource Location Creation
> Time Id
> No se encontró el tipo o no es una constante en tiempo de compilación:
> ButtonPanel. [Generated code (use -keep to save): Path:
> components\ButtonPanel- generated.as, Line: 142, Column: 14]
> FlexTest Unknown 1170796854984 14900
>
> I assume this is a bug in the compiler. Anyone nows a workaround to get
> my class compile or I should try to implement my component without use the
> code behind technique?
>
> Thanks in advance for any insight on this issue.
>
>
> --
> ::| Carlos Rovira
> ::| http://www.carlosrovira.com
> ::| http://www.madeinflex.com
>
>
>
--
::| Carlos Rovira
::| http://www.carlosrovira.com
::| http://www.madeinflex.com
--
::| Carlos Rovira
::| http://www.carlosrovira.com
::| http://www.madeinflex.com