actionscript-3 - cs4 中缺少 insertAt 和 removeAt 向量方法,但存在于文档中
问题描述
我似乎在使用矢量方法 removeAt 和 insertAt 时遇到了一些问题,它们都出现在 as3 的文档中:
“ https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html#insertAt() ”
然而在 adobe flash cs4 中,它们是未定义的并引发错误。cs4 没有这些方法还是文档很差?
解决方案
好吧,除了升级到最新版本的 Flash Player 和 SDK 之外,还有其他选择。这不是一个更好的选择,不是很优雅,但更简单。除非您正在运行一些庞大的数据集,否则VPlus.insertAt(...)实现的性能也不是问题。
执行:
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;
}
}
}
用法:
// myVec.deleteAt(10);
VPlus.deleteAt(myVec, 10);
// myVec.insertAt(15, "Hello World!");
VPlus.insertAt(myVec, 15, "Hello World!");
推荐阅读
- c# - _layout.cshtml 模板中的动态数据可用于使用此模板的所有页面
- apache-spark - 为什么有些运算符返回 DataFrame 而有些运算符返回 Dataset?
- jquery - 使用 jQuery 调用按钮不会收到 JSON 响应
- pandas - Pandas read_csv 从一年中删除前 2 位数字
- c# - WPF 窗口所有权在 50 年代窗口被打破
- php - PHP数据库查询
- jmeter - 如果循环计数大于 1,Beanshell 断言返回不一致的结果
- javascript - 快递/Node.js | 从 glob 调用中生成新的 JSON 对象
- android - 使用适配器时刷新android上的活动
- r - 使用 dbinom() 在问卷中以一定百分比出现答案的概率