ActionScript 2.0 :: Adding A Function To An Array?
Apr 16, 2009
I have 4 buttons and on release of any of the buttons it will call a function. How do you apply a function to any member of an array?I've placed "any_btn" into my code below to show what I mean
I'm newish to Actionscript and need a lesson. Say I have 4 buttons and on release of any of the buttons it will call a function. How do you apply a function to any member of an array?
I've placed "any_btn" into my code below to show what I mean
I want to add a function from an array to my addeventlistener .. so I can add different functions within a loop.. Code: var ary:Array = new Array(one,two); button.addEventListener(MouseEvent.CLICK, ary[i]); Yes I left out the for loop code :: for simplicity sakes.
I have 4 buttons and an empty array. When a button is clicked,I'm adding a element to an array with array.push. However, I want to check the array 1st to see if that element exists. If so, then don't add it. Here's what I have thus far
[Code]...
Now I'm taking it I'd have a conditional statement to see if the element already exists. Unfortunatly I cannot just disable the button. I searched the AS dictionary but oddly enough it doesn't have an easy way to search an array. And IndexOf seems to only work for a string.
I'm new to AS3, but our teacher thinks we're all amazing geniuses and assigned us this project which was due last class. Great, I know, I have to do it even if it's late. Only 5 students out of 28 were able to finish the assignment.[code]Those are all the assignment details he gave us.All I have so far. What I have only adds the array to the list. Nothing much else.[code]Also, when the array prints on a new line, the prior item on the array must not print as show above.
I'm going to post the full code of the two functions, disregard the "fluff" unrelated to the two functions as it is all working flawless, I've tested this HEAVILY and cannot understand why it keeps setting the entire array to undefined!
Code: // processReplace Function function processReplace(transferFiles) { var processArray:Array = transferFiles.slice();
[Code]....
Basically it's supposed to check to see if the file exists and return as true if it does and add it to a replace array, then the replace array is processed into a single string and put into a dialog box through the flash wrapper prompting them to "replace the files or not".
It makes the replace array just fine, it actually even has the right "count" in it but it's setting all the "filenames" to undefined because of the exists = processSearch function.
I even tried to make a new array and run the search just from that one and set the values from the old one and it's still failing.
Is it because of the "break" or can anyone figure it out? Iknow it's hard because you can't use the code
I'm utilizing this code for a photo gallery, and I'm having issues with adding movie clips to arrays. This code compiles with an error stating "Label must be a simple identifier."
Code: //Encapsulating mc for thumbnail images. var mcMaster = new MovieClip();
This program has a green ball (var ballplayer) that theplayer moves around in 3D space using the numpad keys (8, 2, 6, 4)to move the green ball (up, down, right, left). And it also usesthe up and down arrown keys to move the ball along the z-axis.There are also five red balls moving around the screen. As the redballs collide they turn blue. The red/blue balls are z-sorted, sothat the balls closer to the viewer appear in front. The balls allmove around in an invisible cube that they bounce off. Problem: How do I get the player's green ball to be z-sortedwith the other balls? I think I either need to add the green ballto the array called balls before it is sorted. Or create an arrayfor the green ball and then add the two arrays together (if that'spossible) before z-sorting. I tried to add the green ball directlyto the balls array but it didn't seem to work. I'm new to AS3 andprogramming, so I may have made a simple mistake.
Trying to add MC's to the stage from the library using their class name, but its not working out. I'm convinced the below should work, but it does not so there must be something wrong.I get the following error:TypeError: Error #1010: A term is undefined and has no properties.at tesVars2_fla::MainTimeline/frame1()
I have an array, strictly numbers, how could I add... say array[0](value=2)+array[1](value=1) to equal 3? What I come up with is an undefined error, or not a number...
i have a clip on the stage that is 650px wide. i am placing dynamicaly sized clips on top of that clip. when they are created, their names are placed into an array. I am trying to take the items out of the array, find their widths, and then figure out if the width will be greater than 650 if the next clip is placed down. i'm stuck on the loop.
("track1Clips" is the array i have the clips in) here's what i have for (i=0; i<_root.track1Clips.length; i++) { clipName = _root.track1Clips[i];
I have some 2D arrays. I would like to add a 3rd dimension. How do I add this 3rd dimension?
I don't know if I'm stating this correctly but what I would like to do is have an array that holds a bunch of [thumb.jpg, number, bigpic.jpg]. This way all the values entries are related. So if I wanted to get any of these values I could use the same key value.
I don't know if this makes sense. Plus, do I get the values of the 3rd dimension by using [i][2] in a for-loop? I know that [i][0] gets the 1st dimension and [i][1] gets the 2nd dimension.
I've got a combo box adding items from an array. The labels are working just fine, but adding the data with a variable won't work for me. If I put in an actual number, I get that result, but trying to add it with a variable I always get 1 as a result. classData only ever = 1. I can access the array. I know it must be in the syntax.[code]
Using the following tutorials: Photo Gallery using XML and Flash and Adding thumbnails, I have created a photo gallery using xml and flash. The photo gallery features a sliding thumbnail where by onRelease of each thumbnail a larger version of the image is displayed with all images being pulled in from xml info ie:
I have a function shuffling a array of numbers.How can I have each number correspond to a movieclip?Like if I have the number 4 comup first in my array, how can I have movieClip4 show up onto the screen?
The buttons search and find the movie clip in the array flawlessly, but I'm having trouble adding a transition to every movie clip as it is appears. Most tutorials on transitions require a specific instance name, but I want ALL instances to have a transition. Heard the .getChildAt() method is the way to go but cannot find solid guidance on this. Here is the basic code:
Quote:
var myDishArray = [chicken, steak, tuna, pasta, iceCream]; for each (var btn in myDishArray) { btn.addEventListener(MouseEvent.CLICK, onDishBtnClick);
[code]....
how do I properly use the transition manager or add a transition code?
Found some great code that adds Button Event Listeners in a loop. The buttons search and find the movie clip in the array flawlessly, but I'm having trouble adding a transition to every movie clip as it is appears. Most tutorials on transitions require a specific instance name, but I want ALL instances to have a transition. Heard the .getChildAt() method is the way to go but cannot find solid guidance on this. Here is the basic code:
Quote:
var myDishArray = [chicken, steak, tuna, pasta, iceCream]; for each (var btn in myDishArray) { btn.addEventListener(MouseEvent.CLICK, onDishBtnClick);
[Code].....
how do I properly use the transition manager or add a transition code?
I am trying to create a drag and drop activity, and I would like to use an array for easy reusability.I'm new to as3 so I've been adjusting my old as2 code. I am using a component for each of my drags and most of it is working well.My problem is with the event handlers. I use the array to populate all of my 'drags' with the information added in their parameters and this works, but when I create my event listeners it seems to only want to move the last item in the array.My drag components are called drag1, drag2, and drag3.[code]
This obviously is not the way to it. I'm trying to add text from an array to a movieclip. The movieclips are created fine but all populated with the last value in the array. I was hoping to populate each instance with the next value in the array.
I'm trying to find a way to manipulate an array; well, two, actually, but I suspect one solution will fix both.
I have an comma-seperated string of numbers pulled from an xml file, that correspond to the correct answers in a multiple-choice exam app I'm working on. The numbers will always appear low to high, but there could be any number of them up to a maximum of 10, for example:
1,3,5 2,3,5,7,8 1,2,8,9,10
I've seperated the list out into an array, but what I'm eventually going to need to do is to compare this array with another array containing the user's answers. The array of their answers won't necessarily have the same number of values as the array of correct answers.
So, I'm thinking one way round this would be to add zeros in between the numbers in each array, so that they will both have the same number of values. To re-write the example arrays above, these would be manipulated to:
1,0,3,0,5,0,0 (for 7 possible answers) 0,2,3,0,5,0,7,8,0 (for 9 possible answers) 1,2,0,0,0,0,0,8,9,10 (for 10 possible answers)
I can then follow the same process for the array of user's answers (which could be almost anything, but will be limited to the maximum number of responses, i.e. 7 for the first array in the above list), and then run a function to compare the two arrays, which will, after adding the zeros, have the same number of values.
I've made several attempts at this, but keep getting tangled up in loops and if statements... I'm not exactly an Actionscript ninja, as you may have guessed by now!
how I can approach the above, or know of an existing script that will do what I'm after?
I have a MC called Enemy. It contains a monster that pops out at a random time (a timer with animation inside the MC). It stays on the stage for a few seconds and then hides again. If it hides, I want it to be removed and another enemy be added instead. All the monsters are instances of Enemy MC that are inside enemies[] array.[code]