var numberArray:Array= new Array(34,53,2,3,34,26,26,85,3,4,98,2,12);
如何跟蹤它,以便輸出面板將顯示所有其他項目:
"34,2,34,26,3,98,12"
如何跟蹤具有比10的較低值的數字
如何追蹤數組中的偶數?
var numberArray:Array= new Array(34,53,2,3,34,26,26,85,3,4,98,2,12);
如何跟蹤它,以便輸出面板將顯示所有其他項目:"34,2,34,26,3,98,12"
如何跟蹤具有比10的較低值的數字
如何追蹤數組中的偶數?
對於基準和總體教育:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html#map()
// You can init Arrays with [] operator.
var numberArray:Array = [34,53,2,3,34,26,26,85,3,4,98,2,12];
trace(filter(numberArray, evenIndices));
trace(filter(numberArray, belowTen));
trace(filter(numberArray, evenValues));
// In AS3 you can pass method references as function arguments.
// That allows to compose a filtering method, just like Vector.map(...)
// This method will filter the original array
// by the given criteria and return the filtered result.
// Criteria method must accept 2 arguments: element index and value.
function filter(source:Array, criteria:Function):Array
{
var result:Array = new Array;
for (var i:int = 0; i < source.length; i++)
if (criteria(i, source[i]))
result.push(source[i]);
return result;
}
// Returns true if index is an even number.
function evenIndices(index:int, value:int):Boolean
{
return index % 2 == 0;
}
// Returns true if value is less than 10.
function belowTen(index:int, value:int):Boolean
{
return value < 10;
}
// Returns true if value is an even number.
function evenValues(index:int, value:int):Boolean
{
return value % 2 == 0;
}
VAR numberArray:數組= [34,53,2,3,34,26,26,85];
1.How我跟蹤它使輸出面板將顯示每隔一個項目:「34,2,34,26,3,98,12」
getEventIndexiesOfArray(numberArray);
2.How做我跟蹤具有比10更低的值的數字
lenghtLessthanTen(numberArray);
3.如何跟蹤數組中的偶數?
checkArrayHasEventLenght(numberArray);
1. getEventIndexiesOfArray(),用於從陣列獲取事件indexies元件方法。
private function getEventIndexiesOfArray(source:Array):void
{
var resultArr:Array = [];
for (var i:int = 0; i < source.length; i++)
{
if (i % 2 == 0)
resultArr.push(source[i]);
}
trace("Even Indexies Array : " + resultArr.toString());
}
2. lenghtLessthanTen()方法用於檢查該陣列lenght是每種不超過10與否。
private function lenghtLessthanTen(source:Array):void
{
if (source.length < 10)
trace("Array containt lessthan Ten elements");
}
3. checkArrayHasEventLenght()方法檢查陣列containt甚至lenght與否。
private function checkArrayHasEventLenght(source:Array):void
{
if (source.length % 2 == 0)
trace("Array has even number of elenter code hereements");
}
你到目前爲止嘗試過什麼?你能澄清你的#1點(數組與原始數組有什麼意義)? – BadFeelingAboutThis
所以。我嘗試過(numberArray [0,2,4,6,8,10,12]);這給了我一個錯誤: ReferenceError:錯誤#1069:在數字上找不到屬性12,並且沒有默認值。 \t at Untitled_fla :: MainTimeline/frame1() 然後我試着trace(numberArray [0],[2],[4],[6],[8],[10],[12],[14] );它正確地跟蹤了數組中的第一個元素(34),但是它只是列出了我在數組中寫入的數字,而不是數組中我想要的所有其他元素。 – Valtidude
#1寫得有點糟糕,我的不好。我的意思是說:「我怎樣才能跟蹤數組中的其他元素?」 – Valtidude