home |  
Sell Downloads - Ejunkie
open db network by 19.5 degrees
LYRICS | FREE E-BOOKS | SELL DOWNLOADS WITH PAYPAL
 in   
contribute for fun & profit
brink
-Array functions..
-Flash Remoting ..
-str_pad functio..
-Detecting mouse..
-Ltrim, Rtrim an..
-Opening externa..
-Modifying Flash..
-Array functions..
-Smoothing effec..
-Drawing / Vecto..
 
See all Flash Tutorials
 
-Extensions/Plug..
-FLA..
-Flash Software..
-Flash Tutorials..
 
See all Flash
 
All Resources > Flash > Flash Tutorials > ACTIONSCRIPT TUTORIALS
spread the word around  send this page to a friend   read/write comments/corrections/additions comments  rate this 

Array functions for flash

by 19.5 Degrees
 
 
views: 21110 | rating: 4/10
 


// parameters:
// needle: element that needs to be found; haystack: array that needs to be searched
// returns:
// postion of the element, if found; false, if not found
// please note that if the element is found on top of array, the index returned will be 0
// so if you are planning to compare the result against FALSE, you should use like
// if (array_search(needle,haystack)===false) - note the === rather than ==
// using === we can do the exact comaprison (type of value returned is compared too)
// so 0 (integer) will not be equal to false(boolean)

function array_search (needle, haystack) {

var i;
var found=false;

    for (i=0; i<haystack.length; i++) {
        if (haystack[i]==needle) {
            found=true;
            break;
        }
    }
if (found==true)
    return (i);
else
    return (false);
}


// parameters:
// array1 & array2: the arrays for comparison; exact can be true or false which tells the function to compare for length of arrays too
// so if exact is false, comparison for [1,2,3] & [1,2,3,4] will be true
// if exact is true, comparison for [1,2,3] & [1,2,3,4] will be false
// returns:
// true on match; false on mismatch

function array_compare (array1, array2, exact) {

var mismatch=false;
var len;

    if (exact && array1.length!=array2.length) {
        return (false);
    } else {
        len=Math.min(array1.length,array2.length)
        for (i=0; i<len; i++) {
            if (array1[i]!=array2[i]) {
                mismatch=true;
                break;
            }
        }
    }
    if (mismatch==true) {
        return (false);
    } else {
        return (true);
    }

}


« PREVIOUS
  INDEX
NEXT »

spread the word around
read comments

Name Replacement
posted by: Talha Khan
on: Sep 9, 09 6:02 pm

Hi Guys,
i have created a login page for in my flash file but i want to which person is logdin then all the place which need to be replace his name its done automatically i hope you guys understand what i need if any knows about that plz tell me :(
i'll be very thank full to you :)

post reply | read replies (0)



And then it was 2d..
posted by: Sabbie
on: Jun 4, 07 5:47 am

Thanks, updated it for 2d arrays. Returns an array with on the [0] the position of the array that matches and on the [1] the position of the variable inside the array.:

function array_search (needle, haystack) {
var i; var ii; var found=false;
for (i=0; i<haystack.length; i++) {
for (ii=0; ii<haystack[ii].length; ii++) {
if (haystack[i][ii]==needle) { found=true; break; }
}
if (found == true) { break; }
else if (haystack[i]==needle) { found=true; break; }
}
resultSet = [i,ii];
if (found==true) { return (resultSet); }
else return (false);
}

post reply | read replies (0)



New version
posted by: anonymous
on: Feb 17, 06 6:10 am

Since the return gives a standard Break you could make this code much simpler:

function arraySearch(needle_st:String, haystack_ar:Array) {
for (var key_nu:Number=0; key_nu < haystack_ar.length; key_nu++) {
if (haystack_ar[key_nu].name==needle_st) {
return (key_nu);
}
}
return (false);
}

post reply | read replies (0)



Oh yea...
posted by: apotropaic
on: Oct 8, 05 5:35 pm

And just so you know... you're missing {}'s on the if statement checking of found==true.

post reply | read replies (0)



Very useful!
posted by: apotropaic
on: Oct 7, 05 1:37 pm

Thanks a lot for posting this. I too don't understand why an essential function like this isn't built in!

post reply | read replies (0)



read more commentsread more comments   |   read more commentspost comment 



home | contact | contribute | terms of use | privacy policy |