How can I change Label's text using ActionScript?

Hi~ everyone~
I want change Label's text using ActionScript.
Test.mxml
<?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" initialize="init()">
<fx:Script>
  <![CDATA[
   private function init():void{
    var btn:BtnScript = new BtnScript();
    this.addElement(btn);
  ]]>
</fx:Script>
<fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label x="182" y="149" text="Label" id="lbl"/>
</s:Application>
BtnScript.as
package
import flash.events.MouseEvent;
import mx.controls.Alert;
import spark.components.Button;
public class BtnScript extends Button
  public function BtnScript()
   super();
   this.addEventListener(MouseEvent.CLICK, eventHandler);
  private function eventHandler(event:MouseEvent):void{
          // lbl.text = "changed text";
       // HOW CAN I ACCESS LABEL IN MXML FILE?
I'm about to learn flex. Please help me.
Thanks in advanced.

You could achive this very easily(but this shouldn't be used in production code as it'll be difficult to manage as the project grows) by defining a static data member varibale of DataType Label something like below, (modified/added code in BOLD)
Test.mxml
<?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" initialize="init()"
      creationComplete="creationCompleteHandler(event)">
<fx:Script>
  <![CDATA[
   private function init():void{
     var btn:BtnScript = new BtnScript();
     this.addElement(btn);
   private function creationCompleteHandler(event:FlexEvent):void{
     Model.someLabel = lbl;
  ]]>
</fx:Script>
<fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label x="182" y="149" text="Label" id="lbl"/>
</s:Application>
BtnScript.as
package
  import flash.events.MouseEvent;
  import mx.controls.Alert;
  import spark.components.Button;
  public class BtnScript extends Button
    public function BtnScript()
      super();
      this.addEventListener(MouseEvent.CLICK, eventHandler);
    private function eventHandler(event:MouseEvent):void{
          // lbl.text = "changed text";
      // Now use Model.someLabel which is basically 'lbl'.
      Model.someLabel.text = "changed text";  //Mission Accomplished....
Model.as
package
  public class Model
    public static someLabel:Label;
Note: This approach is just to give you an idea but instead should use the MVC pattern.

Similar Messages

  • I was in a Pages Doc and inadvertently had the Caps Lock on. How Can I change all the text I typed from Upper Case to Lower Case?

    I was in a Pages Doc and inadvertently had the Caps Lock on. How Can I change all the text I typed from Upper Case to Lower Case?

    Several protocols may be used.
    Here I describe two of them.
    (1) the one which I use : install and use the "Convert to Lowercase" service available in the free WordService
    (2) copy your text, paste in TextEdit and enter the Edit menu.
    I guess that you will recognize the items in your English menu.
    I apologize but I don't know the English items.
    Yvan KOENIG (VALLAURIS, France) jeudi 16 février 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.3
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

  • How can I change the default text color (black to blue) in Mail on Mountain Lion

    How can I change the default text color (black to blue) in Mail on out going email with Mountain Lion

    There really aren't default outgoing font settings. They are only there for viewing. A workaround I have seen mentioned is to start you signature with the font style you want to use. When you start your message, click in that first part of your signature.
    Something like
    defaults
    Signature

  • How can i change the default text "Query by Example"

    Studio Edition Version 11.1.1.3.0
    how can i change the default text *"Query by Example"* in a Panel Collection
    Thx

    Hi thieto,
    The label you are looking for is af_panelCollection.LABEL_MENUITEM_QBE*
    I'm currently writing a blogpost on this issue. In short, you will have to create a skin resource bundle.
    In the skin definition, refer to this bundle class.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <skins xmlns="http://myfaces.apache.org/trinidad/skin">
      <skin>
        <id>mySkin.desktop</id>
        <family>MySkin</family>
        <extends>blafplus-rich.desktop</extends>
        <render-kit-id>org.apache.myfaces.trinidad.desktop</render-kit-id>
        <style-sheet-name>skins/MySkin.css</style-sheet-name>
        <bundle-name>com.blogspot.lucbors.view.bundles.MySkinBundle </bundle-name>
      </skin>
    </skins>In this class, adjust the label text to your needs.
    package com.blogspot.lucbors.view.bundles;
    import java.util.ListResourceBundle;
    public class MySkinBundle extends ListResourceBundle {
      public MySkinBundle() {
        super();
    @Override
      public Object[][] getContents() {
        return _CONTENTS;
    static private final Object[][] _CONTENTS = {
         {"af_panelCollection.LABEL_MENUITEM_QBE","the text that you want"}
    }More in the blogpost
    Good luck
    Luc Bors
    Edited by: lucbors on Jul 26, 2010 11:39 AM (blogpost finished - URL added)

  • How can I change excel column header using Labile.

    Dear Experts,
                          How can i change excel column header using LabVIEW.
    Thanks for any and all help!
    M.S.Sivaraj.
    Sivaraj M.S
    CLD

    As I said in my previous post, column headers in Excel are merely row 1 cells. May be I missing something here, so please be more explicit with your question.
    I guess you are using the Excel Report tools, and you want to modify an existing sheet. From my limited experience with the Excel Report tools, it is not possible to open an existing woorkbook (except as template...), so the answer to your question should be "Forget it"...
    The work around is to use the example I pointed for you before, and either to write the whole new colum headers as a string array, starting in A1, or to write a single string to a given cell in row 1.
    Hope this helps 
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • HT204411 My boss gave ma a gift card but I can not use it in my country, how can I change country to star using it?

    My boss gave ma a gift card but I can not use it in my country, how can I change country to star using it?

    You cannot change your iTunes country unless you are really moving to another country, nor can you change country association for a gift card.  Give it as a gift to a friend who lives in the country of origin for the card.

  • How can I change Quotation EKPO-AGMEM using BAPI

    How can I change Quotation EKPO-AGMEM using BAPI

    As I said in my previous post, column headers in Excel are merely row 1 cells. May be I missing something here, so please be more explicit with your question.
    I guess you are using the Excel Report tools, and you want to modify an existing sheet. From my limited experience with the Excel Report tools, it is not possible to open an existing woorkbook (except as template...), so the answer to your question should be "Forget it"...
    The work around is to use the example I pointed for you before, and either to write the whole new colum headers as a string array, starting in A1, or to write a single string to a given cell in row 1.
    Hope this helps 
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • How can i change the number im using for FaceTime?

    Everytime i try to call someone on facetime it comes out as another number using the same apple id, how can i change that?

    Hello Lazboy1,
    The following article details both the processes for unlinking a phone number and correcting the lack of a phone number attached.
    iOS 6 and OS X Mountain Lion: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538
    Cheers,
    Allen

  • How can I change the database & schema used by an Application?

    Hi community,
    I am very new on Essbase and I need help to find out how can I change the database connection (and schema) used by the database of an Application. The figure is that I need to point this database to a QA environment (currently it points to DEV).
    If I do a right click over the properties of the database, I can see the following tabs: [ General ][ Dimensions ][ Statistics ][ Modifications ][ Compression ]. However, there is no option to change the database connection.
    Is there a way to do this?
    Thanks in advance for any help! Cheers!

    Are you trying to change a database connection of Planning application?
    Essbase application do not have a relational connection.
    Regards
    Celvin
    http://www.orahyplabs.com

  • How can i change the undisclosed text of Detail Disclosure in a table

    Hi.
    I have a new OAF page, with an advanced table.
    The table has a Detail Disclosure (a row-level Hide/Show in a table).
    By default, the prompt is "Show" or "Hide" for disclosed/undisclosed state.
    I need to change this text to another text, like"payment".
    How can i change the text of the table Detail Disclosure?
    Please help...

    I found this reference in the guide:
    In accordance with BLAF guidelines, the Detail column header text for the detail disclosure column and the Show/Hide link texts within the cells of the detail disclosure column can not be modified.
    I guess it is currently not possible.
    Regards,
    LC

  • How can I change the default text on my homepage tab?

    When my homepage displays it has some kind of weird garbled text in the page tab at the top. Is it just a placeholder? How do I change it?

    It's not "some kind of weird garbled text". It's called Latin, an ancient language. Learned people still speak it. And it's taught in institutes of higher learning.
    It's also used as placeholder text in printing :
    http://www.lipsum.com/
    See the image below where the text originates.
    But you have some issues on your page that can be solved by simply paying attention to what you do.
    First there's an image covering the links. Old Toad referred to that. Move it down, or change the dimensions :
    And that "some kind of weird garbled text" is hidden behind your brochure :
    Read this to learn how iWeb creates the title in the titlebar :
    iWeb uses the textbox in the Header layer of an iWeb page as the title in the browserwindow.
    Do not remove the original textbox, as you cannot replace it other than by selecting another theme and then change it back to the original theme again. Ruining the layout in the process.
    If the textbox in the Header is missing, iWeb uses a textbox down the page in the Content layer. If that textbox is also missing, it uses another textbox. If that fails it uses the pagename in the Sidebar.
    Sometimes you may want a different text in the titlebar and not display it on the page itself. Or not display it at all.
    So use that textbox in the Header layer. Type your text. Then select the textbox. In the Inspector choose T, click a color to open the color palette and drag the opacity slider to 0 (zero).
    Do Command-T to open the font palette and make the font smaller. (Or do Command--(minus)) Also use a font that doesn't change to an image. Arial is a good font. Perhaps do it first before making the text invisble.
    Resize the textbox. You may want to change the height of the Header layer.
    Do Command-Shift-B to move the textbox to the back, possibly behind other objects.
    Next add a optional second textbox to the Header layer and use that one to display text on the page.
    If you want to move the textbox to the front again to make changes, but can't remember the location on the page, drag the area with the mouse to select the objects.
    Deselect objects you do not want to move forward by Command-dragging the mouse over these objects.
    Next do Command-Shift-F to move the textbox to the front. Repeat the steps in reverse order to make the text visible.
    Practice.

  • How can I change a style setter using code?

    I have several Labels using the same Style:
    <Canvas.Resources>
    <
    Style TargetType="{x:Type Label}" x:Key="TitleStyle">
    <
    Setter Property="FontSize" Value="24"/>
    <Setter Property="FontWeight" Value="Bold"/>
    </Style>
    </Canvas.Resources>
    I'd like to change the Setter "FontSize" using some code.
    Any idea?

    You cannot change a setter (or anything else in a style) once the style is in use.
    You can create a new style, remove the current style from the resources, and add the new style as the value for key "TitleStyle".  Elements that used DynamicResource to refer to the style will change, but elements that used StaticResource will not.
    Another approach is to add a trigger to your style.  Then you can get the effect of changing FontSize from code:  just have the code change the value that the trigger reads as its input.
    Yet another approach is to data-bind the FontSize to some property that you can change from code, and attach a ValueConverter to the binding that chooses the size you want.

  • My computer is off and set up on Japanese. I can not login anymore because I type the password in English but the keyboard was set up last in Japanese language.how can I change the language by using the keyboard only so that I can write in English my pass

    Hi
    My computer was shut down. It was set on Japanese Hiragana language before shutting down. Now I want to login with my password in English. Yet, teh keyboard was set in Japanese and thus, I can not login anymore. How can I reset/change from Hiragana Japanese mode to Englsih ( US) with some shortcuts on my keyboard?
    thank you

    Try Apple/Command + space.
    For the future, go to system prefs/accounts/login items and check the box for Show Input Menu on Login Screen.

  • How can I load and save text using FileReference class

    Let me start by saying I have no intention of using php and I can't wait until flash cs5 comes out with its new read/write capabilities
    I want to load and save XML files (stored on my local hard-drive) in AS3.
    I am using the FileReference class.
    Firstly I have noticed that when using FileReference.save if you replace an existing file instead of writing over the file data is appended to the end of the file. Can I make it so the file is overwritten (as it should be) or make it impossible for the user to save in such a situation.
    Secondly I want to load in text from an external file using FileReference.load I know that somehow you use FileReference.browse first to get it to work but I want to know exactly how to do it.
    I have looked for a tutorial about loading text in this manner and have not found one.
    Any help would be much appreciated especially if you could point me in the direction of a relevant tutorial
    Thanks

    the filereference class is for downloading and uploading files.
    if you want to load xml, use the xml class.
    and, if you want to write to an xml file and don't want to use server-side code, wait.

  • How can I change the active Midlet using the '*' cell phone button

    Hello
    I've got a problem trying to do that in J2ME MIDP:
    'I have different class extending Midlet that I want to display one after the other. The change may be done when I click the '*' button of my cell phone'
    For the moment I've created a main class that extend Canvas and which contain a vector of objects extending Midlet.
    I'm able to change the objet which I want to display, but not to display it....
    Is it possible to do that?
    Do you have any idea of how to deal with that?
    Thanks a lot...

    Hello
    Thx for your answer .. but I shouldn't have explain correctly my problem because I don't think this answer it .. sorry
    I need an interaction between a Midlet class and a Canvas class.
    In fact I have several forms, and I need to allow my Canvas class to change the form displayed when a button is pressed.
    But If I have a form in a Midlet , I can display it but can't catch the click on a button.
    And if my Canvas is displayed I don't know how to display the form I want to.
    So is it possible to do that... and if so, how?
    Thank you very much...
    Al161084
    Message was edited by:
    al161084.1

Maybe you are looking for

  • Server error when submitting Apple ID during initial settup

    I'm doing initial setting up of brand new Mac Book Pro w/Retina.  I select hotel WiFi then get to screen for Apple ID.  I type my ID & password but get a server error.  I connect with other devices thru the WiFi but it requires a term agreement befor

  • Can Free add-ons be downloaded with a single Adobe ID and applied to a classroom of computers?

    Can Adobe's free extensions and add-ons be downloaded with a single Adobe ID and applied to a classroom of computers? Specifically a situation where a computer technician has a request from a teacher for a particular free extension (such as Kuler) wh

  • App hang

    Hi all, I hope someone can shed some light on to this - i'm more of a Microsoft techie but have a Mac - just as an end-user; no hating please . Ever-so recently, within the last few days, apps have been hanging really badly. For example, i click Chro

  • 10.3.x to 10.4.x

    Is it possible to upgrade a remote computer from Panther to Tiger using ARD?

  • Use Applescript In  Xcode To Make Timer In Window

    Hi Everyone, I Making An Applescript and cocoa App In Xcode, and i need a Timer that is embedded in a interface builder window how do i do this?