ActionScript 3.0 :: Finding A Function That Checks Periodically If An Array Is Null Or Not?
May 6, 2010How can i do a function that checks periodically if an array is null or not?
View 2 RepliesHow can i do a function that checks periodically if an array is null or not?
View 2 Repliesfinishing a function that checks 6 positions (indiciesOfInterestShape) in a dynamically updated array (productCode) for two types of values; the number 0 or any number between 1 to 8 .I need the result of this function to update the finalNumber variable to a number between 0-6.If a 0 is found at any of the 6 indicies it will mean the final number does not increase.If a number between 1-8 is found at any of the 6 indicies then the final number increases by 1. And seeing as there are only 6 indicies to check the maximum number will only ever be 6.This is what I have so far
// indicies that are dynamically updated 10 19
public static var productCode:Array =
[C,A,1,A,1,A,A,1,A,A,0,0,A,0,0,A,0,0,A,0,0,A]
[code]........
ActionScript Code:
public function draw():Card{
return deck.pop(); //deck = array of Card
}
Does not work. Firstly it runs an error which says
"cannot convert [] to Card"...
Shouldn't it pop() return just ONE element?
Then I correct like this
ActionScript Code:
public function draw():Card{
return deck.pop() as Card;
//deck = array of Card
}
And now I get no errors but the function returns null.... why? If I try this:
ActionScript Code:
public function draw():void{
trace(deck.pop());
//deck = array of Card
}
It prints [Object Card] which is how it should be ....
I am trying to use the following code to convert an object read in from a ByteArray to an Array and store it:
var data:Object = ba.readObject();
var invObjects:Array = data as Array;
In debugging, I find that 'data' is indeed populated with the correct data and takes up memory and is in an Array friendly format. However, invObjects is NULL. How does merely saying 'data as Array' make the holding variable suddenly null?
This should be a simple one. I am running an IF statement that needs to check the 5th value in a pre-populated array. I'm finding it hard to find the right method of searching the array.
[Code]....
indexOf seems to just return where the value is...but I already know where it is! I just want to know WHAT it is! There will also be values that are exactly the same in other positions in the array. I have to focus in specifically on the 5th value.
I am wondering if Flash has a built in way of finding if a value in an array exists. IndexOf only works with string values, but I couldn't find any function that tries to find a value of any data type in an array.
If there isn't one, I will just end up using this:
Code:
contains = function (array, input) {
for (i=0; i<array.length; i++) {
if (array[i] == input) {
return 1;
}
}
};
I am trying not to use my own functions for things that Flash already has built-in, so I just want to double check with you all in case I missed something
So my array has 5 numbers in it and also the ability to add more to it as the user sees fit.I want to be able to display the max and min number in the array. I made a loop but i am not sure how to make it select the highest or lowest number automatically without me selecting it manually by typing it in.This is my code for determining this:
// Determine Min and Max Markfunction maxandminMark(){var markIndex:int;markIndex=(marks.indexOf(marks));if (markIndex != -1){ for (var i = markIndex; i < marks.length; i++) marks[i] = marks[i+1]; trace(maxandminMark);}}}
[code].....
How do I find number of all the series (combinations of an array that have at least 3 consecutive values, like [7,8,9]) and have the longest number of values?
from [3,4,1,2,2] it would be 2 - ([1,2,3,4] twice, but ignore [1,2,3]*2 and [2,3,4]*2)
from [9,6,7,5,8] it would be 1 - ([5,6,7,8,9])
[Code]....
this will create an array ($ranks) that will have these values [2:2, 3:1, 4:1, 9:1]
from this I will be able to multiply the values under 2,3 ad4 4 and multiply them by 3, so I would get 2*1*1 * 3
how to find the consecutive values, and ignore ones that aren't (like the 9)
Is there a method or something that will add up all the values in an array and give me a total?
View 2 RepliesI'm trying to find a simple way to solve this problem: I have an array of integers and need to find the highest value that is unique.Specifically, my array holds player scores. Ex: (4,7,6,5,2,7)I need a function that will give me the highest score that it is not tied with another score. So for the example above, it would return 6 (not 7 since there are two 7's)
View 9 Repliesi was looking at the tutorial Finding Values in an Array here and was wondering if i could replace
Code:
dataValues = [10,9,8,7,6,5,4,3,2];
with a string value thats is read from a text box eg,
Code:
dataValues = [myStringValue];
. myStringValue holds
Code:
"1,2,3,4,5,6,7"
and only finds it if i type in the full value, how do i get it to find each value seperatley after each comma? Everytime i try that it doesnt work correctly.
I have an array with about 80 variables in it and everything is working fine, but I can't seem to figure out how to produce a variable name from the array. Example: I sort my array to get the highest value, then I cannot retrieve the actual name of the variable that holds the value.
[Code]...
I looked into "toString" and toLocaleString but they also gives me the number value.
what to do in order to find the number of sequences in an array? for example: my array is: banana, banana, apple, banana, banana. what shell i do in order to get the numbers: 2,1,2? (2 bananas, 1 apple, 2 bananas).
View 3 RepliesI'm just trying to find the size of a array I created. I know how to find the size of the swf and movieclips with getBytesTotal but that doesn't seem to work for arrays. anyone know of a method to find this or some built in function. I searched google and other search engines but only find the getBytesTotal command for use with MCs.
View 3 Repliesam creating a drag and drop activity which utilizes arrays to populate my 'drag' and 'drop' components with their parameters.So far, I am able to get all the drags to work (with a little a few days ago from the boards showthread.php?t=825222) . My problem now is that I need to register which 'drop' is being hit so that I can update the variables for that drop. However, as the drops are in an array, any time I reference that array it uses the information from the third and final drop, even if drop one or two are hit.Here is my code:
PHP Code:
var usingDrop:Number;
//the vars below are specific to each drop and used to be declared in the drop array - i
[code].....
There is most certainly as easy way of doing this, but for the life of me I can't find it.
How do I determine the array name of an object i.e. when I hover over a certain clip on stage, I want to identify which array it is from.
What's the most effective way to find a number of consecutive elements inside an array?
To give a really basic example, if one had:
var array:Array = [0,1,0,1,1,1,0];
What would be the best way to detect the three consecutive 1s?
I have been playing around with array.some() but it ain't really working out
am developing an application which requires a consecutive searching side to it. Basically, I need a function or a class which takes an array as the parameter, and return the possible 3 consecutive numbers in a 2 dimensional array.For example, if I have this code:
ActionScript Code:
//Global array
var glob:Array=[0,1,2,3,4,5,6,7,8,9];
[code]......
how do you find out in which position a certain value is in an array?
View 9 RepliesIf I've got a public function in a class that I know is being called from an object outside the class, is there any way to access either a reference to the calling object or at least the calling object's type from within that function without passing the caller through as a parameter?
View 3 RepliesI am currently working on a tile based game in Flash, so im working with a two dimensional Array containing the data for the map the player can jump around in. The script is already able to find all the groups within the Array. In the following example Array it groups the left ones and the right using the zero tiles to divide them:
[1,1,0,0],
[1,0,0,1],
[1,0,0,1],
[1,0,1,1]
I am already able to get the corners of the groups, but still they are not in the correct order. As well some corners exist twice.
get the corners in the correct order and how to get rid of the doubles?
I have a simple array and I want to find the most common element in the array, i.e. the mode statistically. This is what I have so far,
var answers = ["c","b","c","a","b","c","a","b"];
var aTotal = 0;
var bTotal = 0;
var cTotal = 0;
for (i=0; i<=answers.length; i++) {
switch (answers[i]) {
[Code] .....
Basically I'm using the curveTo function to draw some lines for flight paths, what I'm not sure how to do is dynamically finding the curve points, so for example if you look at the ryan air site: [URL]
current_line.graphics.curveTo(curveX, curveY, map.mouseX, map.mouseY);
I need to find the curveX and curveY
I tried to search the forum for this problem but my browser every time got too busy to load the search results, so i thought I'll ask it in a new thread.I've made a Chat in Flash CS4 with AS3 - PHP - MySQL.I set a timer to check if there are new entries in the database once in every second. This way the chat window is refreshed every second. Works fine.But I think, if (let's say) 100 people are chatting, the server is bombed by 200 queries (1 for the message and 1 to find who sent it by userid) a second.Is there a way to periodically check the database if there are new entries without making queries? So Flash will ask for new data only if there IS new data available.
View 5 RepliesI want to make a small application that reads an RSS feed.However, this will be part of an installation, thus this is supposed to run "forever". Do you think there is another way than using the Timer class, that would check for new posts on the feed every 15 minutes for example? Do you think this will be a reliable and safe approach?[and an extra questionFor that purpose, is it worth to make an AIR app, or just an executable from the flash player? Do I have some pros/cons regarding memory, resources, etc when using AIR?
View 0 RepliesI am using the following code to Pause, Fade-in & Play a streaming Mp3 from an external site:[code]The problem is that this file is never-ending and ultimately slows the computer WAY down. I'm assuming this has to do with the cache filling up with the never-ending Mp3 file.Does anyone know a way to periodically dump the Cache or... limit the amount of the file loaded into the Cache? Say 3-5 SecondsI am assuming a "DO NOT CACHE" code won't work as the Mp3 is streaming and requires a certain amount for uninterrupted play.
View 4 RepliesI just read the tutorial "Finding Values in an Array". Sure, the code works, but that's only because we are searching arrays the contain a small number of elements. Suppose we have n elements in an array. To search that array for a particular element we may have to do n comparisons. If the array we are searching contains 10 million elements, we have a problem; can you imagine doing "if (this == that)" 10 million times? There's got to be a better way to search the array. Or perhaps we shouldn't use arrays to store the information.
View 9 RepliesIs there an event that IU can assign a function that is called when an swf closes?
View 5 RepliesI'm using Flash CS4 and Actionscript 2 and would like to know if it's possible to call an external script (php script) or take some kind of action (like update a database, write to a file etc) at regular intervals while a video is playing?
1. Is video playing?
2. If yes and time is more than 5 mins (or some inteval) then call a script
3. Sleep and repeat from step 1
I have a swf that connects to Flash Media Server. What I am looking to do, is display the connection status via a green (connected) or red (not connected) icon. I need it to check frequently and update the icon according to the connection status.
I have the following code but it does not work. I have a connect/disconnect button which starts/stops my connection to FMS. That works, but when I unplug my internet connection (thereby making it impossible to be connected to FMS), it still says it is.
Code:
function checkConn()
{
if (nc.connected)
[Code]....