Flex中的全局变量 [英] Global Variable in Flex

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

问题描述

我想用Flex中一个全局变量来工作,它似乎并没有被正常工作。

I am trying to work with a global variable in Flex and it does not appear to be working correctly.

在我的默认MXML文件我宣布以下

In my default mxml file I declare the following

           public var appID:int;

此变量跟踪的会话ID在我的应用程序SQL的目的。 在另一个MXML页我叫下面的code应该更新全局变量的电流ID。

This variable keeps track of the session ID across my application for SQL purposes. On another mxml page I call the following code which should update the global variable to the current ID.

                // Get the ID
            sqlStatement.text =
                "SELECT Max(id)FROM applications";
            sqlStatement.execute();

            var result:SQLResult;

            result = sqlStatement.getResult();
            FlexGlobals.topLevelApplication.appID = result.data[0];

最后,我运行使用ID为参数的SQL更新查询。我的问题是,FlexGlobals.topLevelApplication.appID始终为0,由于某种原因,将全局变量从未得到更新,我已检查,以确保result.data [0]是正确的,但该值永远不会被传递到全局变量。

Lastly I run a SQL Update query using the ID as a parameter. My problem is that the FlexGlobals.topLevelApplication.appID is always 0, for some reason the global variable never gets updated, I have checked to ensure that result.data[0] is correct but the value never gets passed to the global variable.

有谁看到我可能是错在这里做什么? 或者有没有人有一个更好的建议进行跟踪的ID在我的应用程序?

Does anyone see what I could be doing wrong here? or does anyone have a better suggestion for keeping track of the id across my application?

感谢提前任何帮助!

推荐答案

我想创建一个全局类有静态变量:

I like to create a "Globals" class that has static variables:

package {
    public class Globals {
        public static var APP_ID:int;
    }
}

然后访问它在另一个类:

then access it in another class with :

Globals.APP_ID = result.data[0];

这篇关于Flex中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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