Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

actionscript-3 - CS4中缺少但在文档中存在的insertAt和removeAt向量方法(insertAt and removeAt vector methods missing from cs4 but present in documentation)

I seem to be having some trouble with the vector methods removeAt and insertAt, they are both present in the documentation for as3:

(我似乎对向量方法removeAt和insertAt遇到了一些麻烦,它们都存在于as3的文档中:)

" https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html#insertAt() "

(“ https://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/Vector.html#insertAt() ”)

And yet in adobe flash cs4 they are undefined and throw up errors.

(但是在Adobe Flash CS4中,它们是未定义的,并且会引发错误。)

Does cs4 not have these methods or is the documentation poor?

(CS4是否没有这些方法,或者文档不完善?)

  ask by LeToucan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well, there's an option other then upgrading to newest version of Flash Player and SDK.

(嗯,除了升级到Flash Player和SDK的最新版本外,还有其他选择。)

It is not a better option, not very elegant, yet simpler.

(这不是一个更好的选择,不是很优雅,但是更简单。)

Unless you are running some huge datasets, performance of the VPlus.insertAt(...) implementation is not an issue too.

(除非您正在运行一些庞大的数据集,否则VPlus.insertAt(...)实现的性能也不是问题。)

Implementation:

(实现方式:)

package
{
    public class VPlus
    {
        static public function deleteAt(V:*, index:int):void
        {
            // The method cuts a portion of Vector and returns it.
            // We need just the "cut" part, yet it suffices.
            V.splice(index, 1);
        }

        static public function insertAt(V:*, index:int, element:*):void
        {
            // Fix for from-the-end-and-backwards indexing.
            if (index < 0)
            {
                index = V.length - index;
            }

            // Add one more element to the end of the given Vector.
            V.push(null);

            // Shift the Vector's elements from index and on.
            for (var i:int = V.length - 2; i >= index; i--)
            {
                V[i+1] = V[i];
            }

            // Put the new element to its designated place.
            V[index] = element;
        }
    }
}

Usage:

(用法:)

// myVec.deleteAt(10);
VPlus.deleteAt(myVec, 10);

// myVec.insertAt(15, "Hello World!");
VPlus.insertAt(myVec, 15, "Hello World!");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...