参考变量AS3 [英] reference variable AS3

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

问题描述


$ b 示例:

  var1:int = 1; 
varref =var1; (这是引用变量,但当然这不是如何在as3中完成的)

if(var1 == 1)
{
varref = 50
}

如果运行,它会尝试从当前变量varref var1转换为1的一个int,我希望它是引用变量,而不是它自己的变量。



如何做到这一点的一个简单的例子将是伟大的(从我所知道的,可能需要一个对象,所以这种情况的一个简单的对象的例子将是伟大的。)

解决方案

我使用这个类创建引用:
https://github.com/turbosqel/as3SupportLib/blob/master/as3SupportLib/src/turbosqel/data/LVar.as



使用起来非常简单,比如:

  public var item:String =some str; 
{...}
var ref:LVar = new LVar(this,item);
trace(ref.value); // return:some str
trace(my ref is+ ref); //返回:我的ref是一些str
//你可以随时在运行时改变它:
item =new value;
trace(ref.value); //返回:新值

同样的事情您可以使用任何其他数据类型。


I am trying to create a simple AS3 code in Flash Professional CS6 which references a variable.

Example:

var1:int = 1;
varref = "var1"; (this is the "reference" variable, but ofcourse this is not how it's done in as3)

if (var1 == 1)
{
varref = 50
}

If this is run, it would try to make the string from the variable varref which is currently "var1" into an int of "1'. I want it to reference the variable, not be a variable of it's own.

A simple example of how to do this would be great. (From what I know, an object may be needed, so a simple object example of this situation would be great.)

解决方案

I'm using this class for creating references : https://github.com/turbosqel/as3SupportLib/blob/master/as3SupportLib/src/turbosqel/data/LVar.as

Its very simple to use , like :

public var item:String = "some str";
{...}
var ref:LVar = new LVar (this,"item");
trace(ref.value);// return : "some str"
trace("my ref is " + ref ); // return : my ref is some str
// You can always change this on runtime :
item = "new value";
trace(ref.value); // return : new value

Same thing You can do with any other data type .

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

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