作者:今日屎汰濃 | 来源:互联网 | 2023-05-18 02:06
Ihaveaflashlite3applicationwithnavigationconsistingoficonstheusercanbrowseleftorrigh
I have a flashlite3 application with navigation consisting of icons the user can browse left or right through infinitely.
我有一个flashlite3应用程序,导航组成的图标,用户可以无限地向左或向右浏览。
The basic algorithm i'm using now works (and is adequate for this project) however, part of the solution depends on a duplicate of the array of icons. Depending on the number of items in the array, and/or the size of the element contents, this solution could become less efficient. I'm interested in a solution or algorithm(in any language) that could achieve the same thing while being scalable & efficient.
我现在使用的基本算法有效(并且适用于此项目)但是,解决方案的一部分取决于图标数组的副本。根据数组中项目的数量和/或元素内容的大小,此解决方案可能效率降低。我对可扩展和高效的解决方案或算法(任何语言)感兴趣,可以实现相同的目标。
Heres a portion of relevant code in the setter function for mutating the '_selectedItem' property, which:
下面是setter函数中相关代码的一部分,用于改变'_selectedItem'属性,其中:
- Evaluates the current '_selectedItem' and the new '_value'
评估当前的'_selectedItem'和新的'_value'
- Based on step 1 pop,unshifts right, or shift,pops left
基于第1步弹出,向右移位或向左移动,向左弹出
- Repeats step 2 until the icon matching the '_selectedItem' is in the center of the array
重复步骤2,直到匹配'_selectedItem'的图标位于数组的中心
This code runs using 3 arrays:
此代码使用3个数组运行:
- [static] Array of positions. There are 5 icons, 3 are visible at a time, so position 0 is off stage, position 1 is 1/3, position 2 is 1/2 ..
[静态]阵列数组。有5个图标,一次可见3个,因此位置0离开阶段,位置1为1/3,位置2为1/2。
- When instantiating the icons 2 arrays are created: _viewArray & _icons. The order of _viewArray mimics the order to be displayed and _icons is left alone and used for the loop condition checking
实例化图标时,会创建2个数组:_viewArray&_icons。 _viewArray的顺序模仿要显示的顺序,_icons保持不变并用于循环条件检查
///Actionscript2///
public function set selectedItem(value:Number)
{
var w=Stage.width;
if(value > _icons.length-1)
{
value=0;
}else if(value <0)
{
value=_icons.length-1;
}
if(value > _selectedIndex)
{
while(_viewArray[Math.floor(_icons.length*.5)] != _icons[value])
{
var element;
element=_viewArray.pop();
_viewArray.unshift(element);
}
}else if(value <_selectedIndex)
{
while(_viewArray[Math.floor(_icons.length*.5)]!=_icons[value])
{
var element;
element=_viewArray.shift();
_viewArray.push(element);
}
}
for(var i:Number=0;i<_viewArray.length;i++)
{
if(i>=1 && i<= _icons.length-2)
{
_viewArray[i]._visible=true;
}else
{
_viewArray[i]._visible=false;
}
Tweener.addTween(_viewArray[i],{_x:positions[i],_alpha:80,time:.5,transition:'elasticIn'})
}
Tweener.addTween(_icons[(_viewArray.length*.5)-1],{_alpha:100,time:.0,transition:'elasticIn'});
Tweener.addTween(_selectedServiceIndicator,{_alpha:0,time:.3,transition:'elasticIn',onComplete:function() {Tweener.addTween(this,{_alpha:100,time:.2,transition:'elasticIn'});}});
var eventObject:Object = {target:this, type:'SelectedItemChange'};
eventObject.value=value;
for(var key in _serviceData[value])
eventObject[key]=_serviceData[value][key];
dispatchEvent(eventObject);
_selectedIndex=value;
}
1 个解决方案