Extending spark Label

I'm trying to extend a Spark Label so it always has a border with rounded corners like the code below.
<s:Graphic>
<s:filters>
<s:DropShadowFilter color="0x000000" alpha="0.5" distance="7" />
</s:filters>
<s:Group>
<s:Rect width="100%" height="100%" radiusX="5" radiusY="5">
<s:fill>
<mx:SolidColor color="#e0e9f8" />
</s:fill>
<s:stroke>
<s:SolidColorStroke color="#e0e9f8" weight="1"/>
</s:stroke>
</s:Rect>
<s:Label color="#23295D" paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5">
<s:text>This is a Spark Label control with a border drawn by a Rect.</s:text>
</s:Label>
</s:Group>
</s:Graphic>
How can I create a MyLabel.as (extending a spark Label) with the above code in it (i tried a few things but haven't quite got it right).
Or should I be using another component instead of a spark Label.
Thanks in advance
Bodrul Haque

Thanks Alex, I will take a look at SkinnableComponent.
Alternatively, this also gives the desired result (except component needs to be re-measured....still trying to figure how to do that).
The objective was to extend a spark Label and make sure MyLabel always has a border and shading .......and few extra things specific to our needs (which  I haven't added yet).
I've made use of the built in graphics.
public class MyLabel extends Label
  private var dropShadow:RectangularDropShadow;
  public function MyLabel()
    super();
  override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
      super.updateDisplayList(unscaledWidth, unscaledHeight);
       //background
      var backgroundColor:Number;
      var g:Graphics = graphics;
      g.clear();
      backgroundColor = getStyle("backgroundColor");
      graphics.beginFill(backgroundColor);
      graphics.drawRoundRect(-5, -5, unscaledWidth+10, unscaledHeight+10, 10);
      graphics.endFill();
      // Shadow......is their another way???
      if (!dropShadow)
             dropShadow = new RectangularDropShadow();
       dropShadow.distance = 7;
       dropShadow.angle = 45;
       dropShadow.color = 0;
       dropShadow.alpha = 0.4;
       dropShadow.tlRadius = 5;
      dropShadow.trRadius = 5; //cornerRadius;
      dropShadow.blRadius = 5; //cornerRadius;
      dropShadow.brRadius = 5;
      dropShadow.drawShadow(graphics, 0, -5, unscaledWidth+5, unscaledHeight+10);
If I add a couple of these MyLabels into a HGroup (or VGroup) they look squashed. ......so I want to do a invalidateSize() or something

Similar Messages

  • Embedded font not working in Spark Label control?

    Hi,
    I'm trying to use embedded fonts with the Spark Label (formerly SimpleText) control. I'm using SDK 4 build 10485 now, but I could not manage it in Beta 1 neither.
    I'v been playing with cff: true/false, embedAsCFF:true/false but no results.
    I've added my test application where it does work with the Halo <mx:Label> control, but not with the Spark <s:Label> control.
    So, no compiler errors, but the Spark label control shows a serif (Helvetia?) font where it should be sans as does the Halo control.
    Can anybody help me out here?
    Thanks
    Jan
    As I get the message 'the content type of this attachment is not allowed' on uploading the MXML file, here is the code:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo"
        minWidth="1014" minHeight="768"
        backgroundColor="#7B7374">
        <s:layout>
            <s:VerticalLayout paddingBottom="8" paddingLeft="8" paddingRight="8" paddingTop="8" />
        </s:layout>
        <fx:Style>
            @namespace mx "library://ns.adobe.com/flex/halo";
            @namespace s "library://ns.adobe.com/flex/spark";
            @font-face {
                src: url("project/assets/thesans/THSP____.TTF");
                fontFamily: HaloSans;
                fontWeight: normal;
                advancedAntiAliasing: true;
                unicode-range: U+0021-U+007B;
            @font-face {
                src: url("project/assets/thesans/THSP____.TTF");
                fontFamily: SparkSans;
                fontWeight: normal;
                advancedAntiAliasing: true;
                unicode-range: U+0021-U+007B;
                embedAsCFF: true;
            .mySparkSans {
                fontFamily: SparkSans;
                fontSize: 24;
            .myHaloSans {
                fontFamily: HaloSans;
                fontSize: 24;
        </fx:Style>
        <s:SkinnableContainer>
            <s:Label styleName="mySparkSans" text="This should be TheSans but it is not...., notice the characters 'ag'"/>
            <mx:Label styleName="myHaloSans" text="This is TheSans, notice the characters 'ag'" top="100"/>
        </s:SkinnableContainer>
    </s:Application>

    Hi,
    I'm trying to use embedded fonts with the Spark Label (formerly SimpleText) control. I'm using SDK 4 build 10485 now, but I could not manage it in Beta 1 neither.
    I'v been playing with cff: true/false, embedAsCFF:true/false but no results.
    I've added my test application where it does work with the Halo <mx:Label> control, but not with the Spark <s:Label> control.
    So, no compiler errors, but the Spark label control shows a serif (Helvetia?) font where it should be sans as does the Halo control.
    Can anybody help me out here?
    Thanks
    Jan
    As I get the message 'the content type of this attachment is not allowed' on uploading the MXML file, here is the code:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo"
        minWidth="1014" minHeight="768"
        backgroundColor="#7B7374">
        <s:layout>
            <s:VerticalLayout paddingBottom="8" paddingLeft="8" paddingRight="8" paddingTop="8" />
        </s:layout>
        <fx:Style>
            @namespace mx "library://ns.adobe.com/flex/halo";
            @namespace s "library://ns.adobe.com/flex/spark";
            @font-face {
                src: url("project/assets/thesans/THSP____.TTF");
                fontFamily: HaloSans;
                fontWeight: normal;
                advancedAntiAliasing: true;
                unicode-range: U+0021-U+007B;
            @font-face {
                src: url("project/assets/thesans/THSP____.TTF");
                fontFamily: SparkSans;
                fontWeight: normal;
                advancedAntiAliasing: true;
                unicode-range: U+0021-U+007B;
                embedAsCFF: true;
            .mySparkSans {
                fontFamily: SparkSans;
                fontSize: 24;
            .myHaloSans {
                fontFamily: HaloSans;
                fontSize: 24;
        </fx:Style>
        <s:SkinnableContainer>
            <s:Label styleName="mySparkSans" text="This should be TheSans but it is not...., notice the characters 'ag'"/>
            <mx:Label styleName="myHaloSans" text="This is TheSans, notice the characters 'ag'" top="100"/>
        </s:SkinnableContainer>
    </s:Application>

  • Upgrade to Flex 4, Halo theme, embedded font doesn't work for Spark Label

    I'm upgrading an application to Flex 4 from Flex 3.5 using the Halo theme.  If I include a Spark Label in my application the Spark Label does not render the text using the font I defined in my CSS.  My MX Labels render fine.  Here is an example application that replicates my issue.  So,
    Compile and run using Spark theme.  Both Labels render the text with the correct font.
    Compile and run using Halo theme.  Only MX Label renders the text with the correct font.
    Is it not possible to do what I want?
    Thanks
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/mx"
                      minWidth="250" minHeight="250">
         <fx:Style>
              @namespace mx "library://ns.adobe.com/flex/mx";
              @namespace s "library://ns.adobe.com/flex/spark";
              @font-face
                   fontFamily: Verdana;
                   fontWeight: normal;
                   fontStyle: normal;
                   src: url("./style/fonts/verdana.ttf");
                   embedAsCFF: false;
              @font-face
                   fontFamily: VerdanaCFF;
                   fontWeight: normal;
                   fontStyle: normal;
                   src: url("./style/fonts/verdana.ttf");
                   embedAsCFF: true;
              mx|Label
                   font-family: Verdana;
              s|Label
                   font-family: VerdanaCFF;
         </fx:Style>
         <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
         </fx:Declarations>
         <s:VGroup>
              <mx:Label text="My text" />
              <s:Label text="My text" />          
         </s:VGroup>
    </mx:Application>

    I think you might need to set the fontLookup:
            s|Label
                font-family: VerdanaCFF;
                fontLookup: "embeddedCFF";     

  • Adding info Icon to Spark Label

    I am trying to add a info Icon next to a Label in Flex so that when somebody hover over icon, they can see a tooltip but so far no lcuk as i dont see anything like that in spark label control. I m new to skining so do not want to goto that rout but any help with this regard will be greatly appreciated.
    Thanks

    Guessing that skinning is your best bet and it's really not that difficult if you take an hour or two to read carefully any one of a number of articles/introductions on the web.

  • How to dynamically resize a Spark Label?

    If i set the text of a spark label at runtime, the label dont resize automatically. How can i resize the correct width of a spark label at runtime?
    Thanks in advance

    The sample will be helpful to you:
    <fx:Script>
            <![CDATA[
                protected function button1_clickHandler(event:MouseEvent):void
                    // TODO Auto-generated method stub
                    lbl.text = lbl.text + " hi ";
            ]]>
        </fx:Script>
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <s:Label id="lbl" height="20" text="hello" backgroundColor="#FFcc12" x="157" y="83"/>
        <s:Button label="ok" click="button1_clickHandler(event)"  x="177" y="152"/>

  • Spark Label event problem

    Event handler for a Spark.Label control:
    private function onLabelClick(e:MouseEvent):void
    trace(e.target);
    trace(e.target.text);
    First trace returns: '[object TextLine]'
    Then I get this: ReferenceError: Error #1069: Property text not found on flash.text.engine.TextLine and there is no default value.
    What is going on here and how to fix it ??
    And: is it just me or does anyone else have LOADS of problems dealing with all the new 'improvents' in Flex 4??
    (I have to admit that I find the new spark stuff very confusing)

    Hi,
    Try using currentTarget.
    As far as flex 'problems', flex 4 is in beta and as things change this could be considered a problem but its beta which means expect a little confusion
    fundamentally the basic stuff still work the same, spark has a bit of a learning curve which is to be expected when a product becomes more powerful.
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Script>
    <![CDATA[
    protected function label1_clickHandler(event:MouseEvent):void
    lblResult.text = event.currentTarget.text;
    ]]>
    </fx:Script>
    <fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Label x="148" y="85" text="A Label that is clickable" click="label1_clickHandler(event)"/>
    <s:Label id="lblResult" x="148" y="115" text="result"/>
    </s:Application>

  • GetPreferredBoundsWidth of a truncated Spark Label not returning right value

    I am writing a custom layout that autmoatically sets the width of a component to the greater of a "remainder" of what is left for the container and the preferred width of the component, but it is failing when that component is a spark label that has been truncated (maxDisplayedLines).
    I know what the remainder is, and when the Label is not truncated, it all works fine.  However, once the Label is truncated, the getPreferredBoundsWidth method always returns the current size of the truncated label. 
    I need a way to really get the preferred width of the Label, ignoring truncation. 
    I see there is a measureText some folks have used, but the api docs say that shouldn't be used for the spark labels.  Also, I'd prefer to try and keep this at the ILayoutElement level, but if i have to cast to a Label, I can do that. 
    I have already tried to set a larger width, then asking it for its preferred width, but that didn't work. 
    I am going to try the measureText and also trying to unset the maxDisplayedLines, but I am hoping there is a cleaner way.
    Thanks in advance for any help.
    Irv

    quite an elaborate story, but not really clear... sorry..
    this maybe?
    WHERE id=9999
       AND eff_dt='4/19/2010'
       AND name NOT IN('PAD','FIN_ST','FIN_LT')
       or  (ind = 'SHORT' and name = 'PAD')and with parameter:
    WHERE id=9999
       AND eff_dt='4/19/2010'
       AND name NOT IN(<param>,'FIN_ST','FIN_LT')
       or  (ind = 'SHORT' and name = <param>)

  • [svn:fx-trunk] 15267: Cannot set Spark Label or Spark RichText showTruncationTip property at runtime using bindngs or ActionScript .

    Revision: 15267
    Revision: 15267
    Author:   [email protected]
    Date:     2010-04-07 15:57:04 -0700 (Wed, 07 Apr 2010)
    Log Message:
    Cannot set Spark Label or Spark RichText showTruncationTip property at runtime using bindngs or ActionScript.
    QE notes:
    Doc notes: None
    Bugs: partial fix for SDK-25980
    Reviewed By: Gordon
    Tests run: checkintests
    Fix Label styles baselineShift and typographicCase so they work as documented.  The documentation is from TLF.
    QE notes:
    Doc notes: None
    Bugs: partial fix for SDK-25169, SDK-25210
    Reviewed By: Gordon
    Tests run: checkintests
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-25980
        http://bugs.adobe.com/jira/browse/SDK-25169
        http://bugs.adobe.com/jira/browse/SDK-25210
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/Label.as

    I'd have to see the xml to say what, but 1009 is what it says - a null reference has no properties, it is null.
    Try tracing out SampleWebServiceCS.GetMember and you'll quickly see where along your .element.element path you have an error.
    (BTW, I've not used s:Operation before, but is your syntax correct?)
    G

  • How to display trailing white space in spark label?

    I have to display trailing white spaces in spark label but its automatically truncating it.
    Any alternate way? Thanks!

    Thanks for the reply. But still not working

  • Extend spark dropdownlist button to the longest item in dataprovider ?

    Hi,
    simple as stated in the thread's title : I cannot figure out a way to have my spark DropDownLists (no particular skin) extend their width to their longest item width ??
    For instance the following :
    <s:DropDownList id="aglist" width="100%" requireSelection="false"
                                    dataProvider="{model.userAssignedAgents}" labelFunction="agentLabel"
                                    change="aglist_changeHandler(event)" open="{aglist.selectedIndex = -1}"/>
    when layed on a simple spark panel gets the standard DDList button width, about 50px whatever its content, though its items are much longer than that. So when the button is clicked, the dropdown menu shows some ugly scrollbars.
    Do you have any clue ? I've been stuck for hours trying to do what sounds like the very-standard-way-of-setting-dropdownlist-width to me !
    Thanks
    Matt

    Good point.
    The main problem I had with the ComboBox is that I don't want to allow "creation" of new elements, so if the typed text doesn't match any element, instead of selectedIndex of -3 it should just keep the old selection. Plus a few other things.
    Thinking about it, this is probably my best choice, and if I were to extend a class it should probably be this one.

  • How to change a labels text which created at runtime?

    hi,
    i am creating label controls in runtime dynamically and adding them to a group component. this group component is in another custom component and i have lots of custom comp. in my app.
    my question is how can access (via id) and change a labels text whict created at runtime?
    i can change like this but i am setting id's and want to reach via id.
    var lbl:mx.controls.Label = mx.controls.Label(subMenu5.group_subMenu5.getElementAt(1));
    lbl.text = "good job";
    thank you, have a good day.

    First off, if you are already using a Spark Group, I would suggest you use a Spark Label instead of an MX Label. If you want to reference the Labels from the group, loop through the group's elements and check the if the element id matches the Label you want to assign text to.
    var lbl:Label;
    var n:int = myGroup.numElements;
    for (var i:int = 0; i < n; i++)
         lbl = myGroup.getElementAt(i) as Label;
         if (lbl && lbl.id == "myLabel")
              lbl.text = "newText";

  • How to change the backgroud of Flex label

    Hey friend;
    I am trying to change the backgroud color of the flex label
    control but there seems to be no property called background in it.
    I tried it using a css class too but fail.
    Can some one kindly tell me how change the
    background color of the label control.
    Thanks in advance
    Kiran

    I'm afraid you can't, without extending the Label.
    You'll need to use a textArea, or create a custom control,
    probably by extending Canvas. This is not hard at all.
    Tracy

  • Embedded font on Spark Button

    I am using an embedded font for all spark labels. It works fine.
    However, the font is not applied to the button label. If I switch the font to Comic Sans MS then the font is used on the button.
    I can't figure out why this particular embedded font works in all labels, except the button label.
    Any help would be greatly appreciated.
    gkx

    I'm seconding Robs reply here... I had a very similar issue and ended up having to set the fontWeight and fontStyle to match the embedded font. In my case it was normal and normal using a Futura family font.
    So, my overall embed was:
    @font-face {
                                  src: url("assets/fonts/Futura_Book_BT.ttf");
                                  fontFamily: "FuturaCFF";
                                  embedAsCFF: true;
                        @font-face {
                                  src: url("assets/fonts/Futura_Book_BT.ttf");
                                  fontFamily: "Futura";
                                  embedAsCFF: false;
    Then my buttons looked like
    <s:Button fontFamily="Futura"  fontWeight="normal" label="Select"  click="hubSelectionHandler(event)" />

  • Drag selection in spark datagrid?

    Is there an easy way to enable a spark DataGrid to use drag selection, similar to how you can select cells in Excel or Google Docs? Or will I need to track mouse movements and manually manipulate the selectedCells?
    Thanks!
    -Aaron

    Couldn't find a built in way to do this, but it turned out to be pretty easy thanks to the GridEvent classes that solve the challenge of know what row/column index the mouse is interacting with. My final solution:
    A class that extends spark::DataGrid
    private var _allowDragSelection:Boolean = false;
    private var dragSelectionAnchor:CellPosition;
    private var dragSelectionStarted:Boolean;
    * If true and selectionMode is GridSelectionMode.MULTIPLE_CELLS the user can drag their
    * mouse to select a rectangular area of cells, just like Excel or Google Docs.
    public function get allowDragSelection():Boolean { return this._allowDragSelection; }
    public function set allowDragSelection(value:Boolean):void {
              if(this._allowDragSelection == value)
                        return;
              this._allowDragSelection = value;
              if(this.allowDragSelection)
                        this.addEventListener(GridEvent.GRID_MOUSE_DOWN, this.handleGridMouseDown);
              else
                        this.removeEventListener(GridEvent.GRID_MOUSE_DOWN, this.handleGridMouseDown);
    private function handleGridMouseDown(e:GridEvent):void {
              if(this.selectionMode != GridSelectionMode.MULTIPLE_CELLS)
                        return;
              this.dragSelectionAnchor = new CellPosition(e.rowIndex, e.columnIndex);
              this.dragSelectionStarted = false;
              this.addEventListener(GridEvent.GRID_MOUSE_DRAG, this.handleGridMouseDrag);
              this.stage.addEventListener(MouseEvent.MOUSE_UP, this.handleDragMouseUp);
    private function handleGridMouseDrag(e:GridEvent):void {
              // don't start processing selection drag until mouse has left the selection anchor
              if(!this.dragSelectionStarted && e.rowIndex == this.dragSelectionAnchor.rowIndex && e.columnIndex == this.dragSelectionAnchor.columnIndex)
                        return;
              // once started, process changes even if the user drags back over the anchor
              this.dragSelectionStarted = true;
              // local to avoid expensive getter cost
              const selectedCells:Vector.<CellPosition> = e.grid.selectedCells;
              // determine the selection rectangle from the anchor to the current cell
              const rowFromIndex:int = Math.min(this.dragSelectionAnchor.rowIndex, e.rowIndex);
              const rowToIndex:int = Math.max(this.dragSelectionAnchor.rowIndex, e.rowIndex);
              const colFromIndex:int = Math.min(this.dragSelectionAnchor.columnIndex, e.columnIndex);
              const colToIndex:int = Math.max(this.dragSelectionAnchor.columnIndex, e.columnIndex);
              // create new cell positions selection vector, and track if any new cell is added
              var cells:Vector.<CellPosition> = new Vector.<CellPosition>();
              var cellsChanged:Boolean = false;
              for(var row:int = rowFromIndex; row <= rowToIndex; row++){
                        for(var col:int = colFromIndex; col <= colToIndex; col++){
                                  var cell:CellPosition = new CellPosition(row, col);
                                  cells.push(cell);
                                  cellsChanged = cellsChanged || !selectedCells.some(function(c:CellPosition, i:int, v:Vector.<CellPosition>):Boolean {
                                            return c.rowIndex == cell.rowIndex && c.columnIndex == cell.columnIndex;
              // assign the new selection only if it changed (Flex is pretty slow here with big selections)
              if(cellsChanged || selectedCells.length != cells.length){
                        this.selectedCells = cells;
                        // maintain the selection anchor for any following SHIFT click selection
                        this.grid.anchorRowIndex = rowFromIndex;
                        this.grid.anchorColumnIndex = colFromIndex;
    private function handleDragMouseUp(e:MouseEvent):void {
              this.removeEventListener(GridEvent.GRID_MOUSE_DRAG, this.handleGridMouseDrag);
              this.stage.removeEventListener(MouseEvent.MOUSE_UP, this.handleDragMouseUp);
    Cheers.
    -Aaron

  • Japanese indication of Label and Button is strange in Android5.0.1.

    A screen of attachment is Label, TextArea, Button in turn from the top.
    TextArea is normally indicated, but all hiragana, katakana and kanji aren't shown to Label.
    Hiragana and katakana aren't shown to Button.
    Nexus7(2013) Android5.0.1 AIR15.0.0.381
    AIR Simulator

    Hi Ankit,
    Not sure if this is a right place to raise, I also found that the Spark Label is not rendering Chinese characters correctly. Attached is a screen shot for your reference.
    Testing Environment
    Android 5.0.1
    Apache Flex 13
    Adobe AIR 15
    The same application works well on Android 4.x.
    Cheers
    Vicker

Maybe you are looking for

  • @postconstruct doesn't work in managed bean

    Hi, I'm using JBOSS 6, JSF 2 and EJB 3.1, i have an ear with - EJB folder (@postconstruct is working) - JSF folder with manged bean where @postconstruct doesn't work This my manged bean : package com.galhauban.geriex; import java.util.ArrayList; impo

  • Printing a CD cover...

    When I try to print a CD cover the text is printing overlapped on each other. The album cover art prints fine, just the text is unreadable. This happened with a previous version of iTunes, but when I upgraded, it worked. Now when I recently upgraded

  • Attachments With A Text Msg?

    Is there a way to add an attachment to a text message? Try as I might, I have been unable to figure out how to do it.

  • Skewing a movie clip using 3D rotation tool

    Check out the swf below.  I'm trying to skew the images as they approach the edges of the screen.  My goal is to create a 3D effect so the images appear to be falling back to a vanishing point.  Any suggestions?  

  • Crash when rendering

    I am running a CS4 9.0.2.42 trial. I successfully rendered my video which is about 4 mins long. Then I needed to make some changes, which I did and tried to render it again. Now if freezes part way through the rendering process. So I tried to break t