Flex:更新标签的文本,这是一个变量 [英] Flex: Update a label's text, which is a variable

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

问题描述

我有一个标签,当你点击一个按钮时,它会从一个 var 中获取它的值.该 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 的文本为 Null(它不会给出错误,在我的情况下只是Null").这是我目前的情况.

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% 确定我理解您的问题,但是如果您的变量被声明为可绑定",无论您的脚本更改其值还是按钮,标签的文本属性将在绑定时跟随.

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>

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

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