AS3在进入if语句之前计算flashVar的数量
我正在使用 AS3 创建一个简单的图像查看器,并从 HTML 中的 flashVars 获取图像 URL。我想使用 if
参数让它在只有一个 flashVar 时执行一个函数,如果有更多的话则执行另一个函数。
我让它可以很好地读取 flashVars,并且可以整天编写 if 语句,我遇到的麻烦是计算
从 HTML 传递的 flashVars 的数量。这是我正在尝试做的事情的一个真正的简化版本(这不起作用
,因为我无法找出要遵循的正确过程):
var numberOfVars:Number = 0; // to store the number of flashVars
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters; //get the flashVars
for each (paramObj in LoaderInfo(this.root.loaderInfo).parameters){
numberOfVars + 1;
}
var tf:TextField = new TextField();
addChild(tf);
tf.text = numberOfVars.toString(); // this returns '0' when runningn this code
if (numberOfVars < 2){
//do this
}
else {
//do this
}
感谢你们的帮助。
克里斯
I am creating a simple image viewer using AS3 and getting image URLs from flashVars in the HTML. I want to use an if
argument to have it perform one function if there is only one flashVar and another if there are more.
I have it reading the flashVars fine and can write if statments all day long, the trouble I am having is counting the number
of flashVars being passed from the HTML. here is a real dumbed down version of what I am trying to do (which doesnt work
because I can not figure out the correct process to follow):
var numberOfVars:Number = 0; // to store the number of flashVars
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters; //get the flashVars
for each (paramObj in LoaderInfo(this.root.loaderInfo).parameters){
numberOfVars + 1;
}
var tf:TextField = new TextField();
addChild(tf);
tf.text = numberOfVars.toString(); // this returns '0' when runningn this code
if (numberOfVars < 2){
//do this
}
else {
//do this
}
thanks for your help guys.
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你会想要增加 numberOfVars
看起来你有这个:
当你应该有这个:
这只是写这个:
或这个:
You would want to increment numberOfVars
Looks like you have this:
When you should have this:
which is just short way of writing this:
or this:
只需使用
for(key in object)
循环来跟踪存储在root.loaderInfo.parameters
上的变量数量。另外,您的一位操作员做错了:
您正在寻找以下其中一项:
Just use a
for(key in object)
loop to track the amount of vars stored onroot.loaderInfo.parameters
.Also, you've done one of your operators wrong:
You're looking for one of the following:
我将在这里对条件逻辑提供稍微不同的看法。与其根据变量的数量来对变量做出反应(这会带来大量出现不可预测结果的机会),为什么不根据变量的实际情况来制定条件语句呢?这是我的标准 flashVar 流程:
显然,这只是测试某个值是否存在,但可以轻松更改它以根据这些结果调用某些功能:
我不知道您要做什么正在努力实现这一目标,而这可能还很遥远。但我想我应该插话;)
干杯!
I will offer a slightly different take on the conditional logic here. Instead of reacting to variables based on how many there are (introducing plenty of opportunity for unpredictable results) - why not base your conditional statements on what the vars actually are. This is my standard flashVar process:
This, obviously, is just testing for the presence of a value, but it could be easily altered to call some functionality based on those results:
I don't know what you are trying to achieve, and this may be way off. But I thought I'd chime in ;)
Cheers!