English 中文(简体)
• 如何在SAP3[复制]中提及变数行为
原标题:How to make variable act like reference in AS3 [duplicate]
This question already has answers here:
Closed 12 years ago.

Possible Duplicate:
Can you have "ByRef" arguments in AS3 functions?

AS3的主要类型按价值而不是参考。 是否有办法推翻这一行为,并参照某些变量? 采用以下法典:

for (var i=0; i<4; i++) {
    for (var j=0; j<4; j++) {
        if(i==0 && j==0){
            switch(currentRotation){

            case 0:
                var1 = j; //I want var 1 to be a reference to j, not the value of j
                    break;

            }
        }
        if(someArray[var1][var2]){
            //stuff
        }
    }
}

如果是这样,我猜测,我只得复制和复制这部法典几度:

增 编

最佳回答

You may cheat a bit. Wrap j into some object:

var obj = {j: 0};
for (var i=0; i<4; i++) {
    while (obj.j < 4) {
        if(i==0 && obj.j==0){
            switch(currentRotation){

            case 0:
                //...
                    break;

            }
        }
        if(someArray[var1][var2]){
            //stuff
        }
        obj.j++;
    }
}
问题回答

没有,只有价值才能通过原始类型。

甲型六氯环己烷的主要类型实际上通过参考,但如通过数值,则不可改变。

对于有兴趣了解技术细节的读者来说,《行动》在内部将原始价值作为不可改变的物品。 它们被储存为不可改变的物体的事实,意味着通过提及实际上与价值转移相同。 这减少了记忆使用量,提高了执行速度,因为参考资料通常大大低于价值观本身。

rel=“nofollow”http://help.adobe.com/en_US/Action/

因此,你能够战胜这种行为。





相关问题
Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签