软硬度:更新标签的文本,至极是一个变量 [英] Flex: Update a label's text, wich is a variable

查看:112
本文介绍了软硬度:更新标签的文本,至极是一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有得到它是从一个VAR值,当你点击一个按钮的标签。该变种已经宣布:

I have a label that get it's value from a var when you click on a button. The var has already been declared:

public function clickevent
{
label.text = aVariable; 
}

现在我知道,如果我有一个标签,像这样的:

Now I know that if i have a label like this:

<s:Label id="label2" text="{aVariable}"/> 

和aVariable是空的,LABEL2的文本是空(它不给一个错误,只是空,在我的情况)。这是我目前的状况。

and aVariable is empty, label2's text is Null (it doesn't give an error, just "Null" in my situation). This is my current situation.

我想知道的是,当我后来就aVariable的值更改为一个字符串hasChanged为例。该LABEL2的文本也应更改为hasChanged,而无需按下一个按钮或任何东西,使这个更改的用户。如何才能做到这一点?

What I'd like to know is when I later on change the aVariable's value to a string "hasChanged", for example. The label2's text should also change to "hasChanged" without the user having to push a button or anything to make this change. How can this be done?

推荐答案

我不是100%肯定我明白你的问题,但如果你的变量声明为绑定,不管你的脚本改变其价值或按钮,标签的文本propertie将遵循因为它是绑定。

I'm not 100% sure I understand your question but if your variable is declared as "bindable", no matter if your script change its value or a button, your text propertie of the label will follow as it is binded.

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[
            [Bindable]
            private var aVariable:String;

            protected function button1_clickHandler(event:MouseEvent):void
            {
                aVariable = "My new value";
            }
        ]]>
    </fx:Script>

    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <s:Label text="{aVariable}"/>

    <s:Button label="Click me" click="button1_clickHandler(event)"/>

</s:WindowedApplication>

这篇关于软硬度:更新标签的文本,至极是一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆