Iterating Through An Array And Selectively Deleting Items
Dec 30, 2010
I'm making a very short text adventure, not one that will be all that fun, but just so I can learn a little as3. So I was designing a system that splits the persons input into an array of words, and then goes through and takes out unimportant words like "on." To test this out, I quickly (and messily) coded it up, and the only thing you can do is sit on a box. but it doesn't seem to be working. if you type "sit box" it works, but "sit on box" does not.
I have a small problem with iterating over array. I would like to iterate through items gathered in my array in a way of "one at a time" in each muse click event but whenever I'm using a simple loop it just takes all my elements to process. Is there a way to make a single iteration in each click and still increment the index value in loop?
I want to iterate over an ArrayCollection in Flex while there can be items added and removed.
Since i didn't find a way to use a "classic" Iterator like in Java, which would do the job. I tried the Cursor. But it doesn't really work the way i want it to be ;) So how do I do it nicely ?
var cursor:IViewCursor = workingStack.createCursor(); while (!cursor.afterLast) {
I am using Adobe Flash CS4 Professional. I have a simple navigation menu that I am trying to edit. I may be in the wrong place in the file, but when I open the .SWF files I can see the lines of code and I can see the actual navigation menu as it appears on our web site. I have not been able to figure out how to change / edit / delete the line inthe drop down menu that I want to delete on our web site.
I am creating an option in my application to create a PDF report based on the results from the application.The results are represented as an ArrayCollection of XMLList objects, which I am using to populate a BarChart.To create a screenshot of each result (as a PNG), I am loading the Results Window (a Title Window) and hiding it (visible = false). I am using AlivePDF to add the capture to a PDF report.
I have been using a Timer to iterate through the results, load each result to the chart, create a delay, and then capture the image and add it to the report.
UPDATE.Currently, I am able to iterate through the results (using the Timer), but the chart does not refresh properly before capturing the screenshot and saving as PNG.Essentially,I am trying to see if there is any other possible solutions for iterating through the results and creating a delay so that I may be able to load a result to the chart, capture the screenshot, and add it to a PDF.Is there any other way to do this in Flex?Initially, I was thinking of iterating through the results array using a for loop,but this was not working due to the fact that the results were not loading in time before capturing the screenshot of the chart.
I'm trying to figure out if this is possible?lets say I'm trying to remove the value "3"
Code: Select allvar myArray:Array = new Array("1","2","3","4","5"); myArray.pop(); // removes the last value "5" myArray.shift(); // removes the first value "1"
How do you remove the value 3 and still have the correct lenght?
Is there a way to delete a specific value in an array? For example, the array:"Banana Peel,Hippopotamus Leg,Computer Wire,Keyboard"Would there be any way to delete just "Computer Wire" from the array? I found the Array.splice thingy, but it seems that you need to know the index of the thing. Therefore i guess my question is: Is there any way to find the index of a particular value.In the thing I am making, the value could be at any index in the array (it is put in place by the user), so I could not just say Array.splice(2,1,)
Actionscript Code: var gameObjectArray:Array = new Array();var gameTimer:Timer = new Timer(25);gameTimer.addEventListener(TimerEvent.TIMER, gameLoop);gameTimer.start();
[code].....
So every 25 milliseconds, a block is being created and it pushed into an array. The for loop cycles through the array and moves the x by 1 for each object in the array. If the x reaches past 300 pixels, then I want to delete the object from the game entirely. The way I'm doing it now yields an error, so what am I doing wrong and what should it look like inside of the "if (i.x > 300)" stuff?
how to delete an element from an associative array? Splice doesn't work and I tried using the delete action but this doesn't produce the desired result....the element's properties become undefined.
x = new Array(); x['kamil'] = new Object(); x['kamil'].name = "kamil"; x['madzia'] = new Object();
[Code]....
How to remove any element from that array when instead of indexes we have names; such as kamil or madzia. pop, shift, slice, splice and so on... dont work at all.
I'm working on a game for my flash class, where you a question pops up and asks you the name of a US state and you guess the state. I have created the 50 states as buttons with the questions. Each state is in its own frame and i need a way to randomly select a state.
After the game begins i need to crate an array with the frames of all states and then have a random() function select a frame from the array and display the question on the screen. After that it needs to delete the frame from the array so the random() function cannot select the same question twice. Once that is done and all of the data is gone from the array then it needs to move on to a different frame where the total number of questions correct is calculated and its display on the screen.
What I'm trying to do is show a little explosion movie clip each time the player's ship gets hit by enemy fire. I thought it would be similar to how my shield powerup works, but apparently it isn't -- or it is, and I'm just doing something wrong. Here's the code for the shield business, to give an idea of how things are set up. The shield movieclip is nested inside of the ship movieclip, and it only becomes visible when the ship collides with the shield powerup icon. It runs for 240 frames, fades out and disappears. What I'd like to do is have a multi-frame explosion movieclip inside there as well, which appears, plays once, then disappears, whenever the ship is hit.
I'm making flash game, and I have the staged masked so your character can only see part of it. However, I don't want the entire stage masked, I only want the "Game Area" masked. Imagine my stage is 800x800. However, the "Game" only takes up the area at the top, 800 by 600. There are 200px at the bottom where I can use for chatting, or displaying information, as your character walks around the game area.
The issue is, I setup my mask, and it masks /everything/ on stage. Even if I have something outside the "game area", it is still hidden behind the mask. So my question is, in my flash application, how can I use my mask in the "game area", and not have other parts of my application affected? Can I selectively put items above the mask?
Edit: Clarifying. My game starts by initialzing the GameScreen object: game = new GameScreen(); //800 x 600. Declared as class variable game.y = 40; addChild(game);
[Code]....
So now, we have my game setup, with a circular hole in the mask and the player can see his character. However, also when the Game Screen object initializes, it places an infomation bar on the screen. This information bar also gets hidden by the mask. The player cannot see it. The issue is, I want this bar (and other components to be added later) to be visible to the player at all times. I can't simply change the shape of the "hole" through the mask, because it moves with the player. So how can I allow that information bar to be seen by the player, while still hiding the game area?
I'm currently working on a Flash site with AS2 (I made the switch to Flash CS3 in the middle of the project and kept things in AS2 to avoid any potential problems). [URL]As you can see by going to the link the preloader takes a loooooong time. After going through the preloader tutorials I have still yet to find an effective way of making the preloader at the begging load only the opening animation or any other preloaders after that load a specific movie.
I am working on trying to collect data within an array (which works) and this data is collected when a button is pressed or selected. I also want the ability to remove an item from the array if the button is pressed again. Currently, I have these buttons dynamically generated and everything works well. The buttons have ids applied to them. SO what I am trying to get working is, if I select button 0, 2, 3 (0 indexing), the data array created holds [A., C., D.]. I want to remove A. after I click button 0. Instead, it seems to cause problems. What I am doing wrong with splicing??? trace statement:
A. items so far selected selected items are: 0 A.,C. items so far selected
I'm so proud of myself. I figured this out all by myself and thought I would share. (If you can't tell, I'm new to AS) I needed a way to grab an item in a specific location and have it return an array of items. Here is how I did it:
I have an array that contains movieclips. All of the movieclips have te type and they are all positioned on the stage next to eachother.
Above the displayed movieclips i have 3 buttons, each simbolizing a type, what i want to do is: i click on one of the buttons and all of the movieclips that dont match the right type should be removed from the stage, the remaining movieclips should then tween so that they are next to eachother again. If i click the button again then the movieclips should be displayed again to where they were and should all be positioned again next to eachother.
I'm a bit green when it comes to code and I have a specific thing I need to do which has had me going round in circles (no laughing at the back!). It must be pretty simple but I'm stumped! Basically I have 6 movieclips on the timeline with instance names 'btn1', 'btn2' etc to 'btn6'. These movieclips have an "on" and an "off" state (frame labels)