需要在ActionScript 3的一些阵列的帮助阵列、ActionScript

2023-09-09 21:54:11 作者:死了的心最干净

我很新的数组的概念......所以我需要一点帮助,理解和执行它....

i am very new to concept of array...so i need a bit help understanding and executing it....

所以我有5个按钮...

so I have 5 buttons...

周一 - 周五

现在,当有人presses我想要的程序跟踪这只是pssed $ P $一天的一个按钮。可有人请解释我一步一步在做什么,为什么?

now when somebody presses one of the buttons I want the program to trace the day that was pressed only.. can somebody please explain me step by step on what to do and why?

我使用Flash的ActionScript 3 .. 这是pretty的大部分我唯一知道该怎么办......我已经尝试了一些onlint TUTS但他们也不是很清楚。

I am using flash actionscript 3.. this is pretty much the only thing I know how to do...I've tried some onlint tuts but they weren't very clear

var days: Array ["mon", "tues", "wed", "thurs", "fri"];

推荐答案

您的阵列创建错误在您的文章。试试这个:

解决方案
Your Array was created wrong in your post.  Try this:

或者你也可以创建像这样,使用Array类的push()方法:

var days:Array = ["mon", "tues", "wed", "thurs", "fri"];

or you could also create it like this, using the push() method of the Array class:

追踪在您的文章中数组的值:

var days:Array = new Array(); days.push( 'mon'); days.push( 'tues'); days.push( 'weds'); days.push( 'thurs'); days.push( 'fri');

to trace the values of the array in your post:

阵列的内容被存储在阵列的索引。数组的索引总是从0开始。

trace( days[0] ); // returns "mon" trace( days[1] ); // returns "tues" trace( days[2] ); // returns "wed" trace( days[3] ); // returns "thurs" trace( days[4] ); // returns "fri"

阵列的具有长度。空数组的长度为0。如果阵列具有在它的至少一个项目时,长度为1,随着添加更多的项目。要遍历您的阵列来获得的值做到这一点:

The array's contents are stored in the array's "indexes". An array's index always starts with 0.

Array's have a length.  An empty array's length is 0.  If the array has at least one item in it, the length is 1 and increases as you add more items.  To loop through your array to get the values do this:

数组是任何编程语言的强大和重要组成部分。您可以从阵列中删除项目,添加项目,在一个特定的索引中删除的特定项目,通过名称来清除一个项目,结合阵列,以及更多。你会从中受益看着这链接和研究属性和数组类的方法。一旦你了解如何操纵阵列的窍门,你永远不会现在怎么样,你存在没有他们!

for(var i:int = 0; i < days.length; i++) { trace( days[i] ); }

有许多方法来一个按钮与一个特定的数组索引相关联。通过 Dr.Denis McCracleJizz 提供的答案是单向的,但如果你像你说的是作为新AS3,它似乎有点势不可挡,因为它使用的几个概念,你可能还不熟悉。让我看看,如果我可以把它简化一下,虽然这会令codeA位较为漫长的:

Arrays are a powerful and essential part of any programming language. You can remove items from the array, add items, remove a specific item at a specific index, remove an item by name, combine arrays, and lots more. You'd benefit from looking at this link and studying the properties and methods of the Array class. Once you get the hang of how to manipulate Array's you'll never now how you existed without them!

There are many ways to associate a button with a particular array index.  The answer provided by Dr.Denis McCracleJizz is one way, although if you are as new to AS3 as you say, it might seem a little overwhelming as it uses several concepts you may not yet be familiar with.  Let me see if I can simplify it a bit, although this will make the code a bit more lengthy:

如果你熟悉的对象,你可以创建一个对象,为每个同时按住按钮和按键标识和存储这些阵列中的按钮:

mondayButton.addEventListener( MouseEvent.CLICK, onClickDayButton ); tuesdayButton.addEventListener( MouseEvent.CLICK, onClickDayButton ); function onClickDayButton( e:MouseEvent ):void { if( e.target.name == 'mondayButton') { trace( days[0] ); } else if( e.target.name == 'tuesdayButton') { trace( days [1] ); } // and so on... }

If you're familiar with objects you could create an object for each button that hold both the button and the button id and store those in an array:

您可以进一步通过按钮右进dayButtonArray,而不是一个ID相关联的当天一共跳过天阵并添加简化上述对象的方法

You could further simplify the object method above by skipping the days array altogether and adding the day associated with the button right into the dayButtonArray instead of an id:

var dayButtonArray:Array = new Array();

var mondayButtonObject:Object = new Object();
mondayButtonObject.button = mondayButton;
mondayButtonObject.day = "monday";
dayButtonArray.push( mondayButtonObject );


var tuesdayButtonObject:Object = new Object();
tuesdayButtonObject.button = tuesdayButton;
tuesdayButtonObject.day = "tuesday";
dayButtonArray.push( tuesdayButtonObject );

// and like above, the rest of the days here

// then loop through them and set the mouseEvent

for(var i:int = 0; i < dayButtonArray.length; i++)
{
   dayButtonArray[i].button.addEventListener( MoouseEvent.CLICK, onClickDayButton );
}

// and the function each button calls to

function onClickDayButton( e:MouseEvent ):void
{
    trace( evt.target.day );
}

现在都拿到一样复杂的 Dr.Denis McCracleJizz的的答案。他绝对是值得看的为好。

Now were getting as complicated as Dr.Denis McCracleJizz's answer. His is definitely worth looking at as well.