PDA

View Full Version : [as]loop out



cki
February 28th, 2005, 06:56 PM
After discovering this php loop


//ARRAY LOOPING EXPERIMENT BASED ON FOUNDATION FLASH PHP SCRIPT.
/*
// Now we loop through each entry in our arrays looking for a valid match
for ($count = 0; $count < count($usernames) && $matchFound == false; $count++) {

// If username and password matches entry...
if ($username == $usernames[$count] && $password == $passwords[$count]) {

// Get the user's message and indicate we've found a match
$message = $messages[$count];
$matchFound = true;
}
}
*/


I'm attempting to do the same with AS, running into undefined



matchfound = false;
var message = new Array("Fun", "Love", "Laugh");
var user = new Array("Alice", "Shelia", "Cathy");
var pass = new Array("Disco", "Tango", "Samba");
for (var i = 0; i<user.length && matchfound == false; i++) {
if (users == user[i]&& password == pass[i]) {
}
trace(users[i]);
}


Can I do this?

senocular
February 28th, 2005, 07:00 PM
what is users and where is it defined? if its the user input name, then you shouldnt be trying to access it like an array ... unless you're confusing users with user

cki
February 28th, 2005, 07:17 PM
what is users and where is it defined? if its the user input name, then you shouldnt be trying to access it like an array ... unless you're confusing users with user
Below is the following php script in its whole:


<?
/************************************************** *********
File: login.php

From: Chapter 2
Foundation PHP for Flash by Steve Webster
URL: http://www.phpforflash.com
************************************************** *********/

// Create and fill username and password arrays.
// We also want to return a custom message for each user so
// we'll fill another array with those messaged
$usernames[] = "Steve";
$passwords[] = "nottelling";
$messages[] = "Welcome, oh masterful one!\nHow are you today?";

$usernames[] = "Matt";
$passwords[] = "itsasecret";
$messages[] = "Hello Sir Matt, knight of the purple jelly table! Did you bring my rubber wallpaper?";

$usernames[] = "Alan";
$passwords[] = "nmof2";
$messages[] = "Ah, hello Alan.\nYou'll be glad to know Chapter 2 is *nearly* finished!";


// Check that a username and password have been passed...
if (!isset($username) || empty($username) || !isset($password) || empty($password)) {

// If not tell Flash movie that we've failed and return error message
print "&result=Fail&errorMsg=" . urlencode("You need to supply a username and password");
exit;
}

// Set a variable so we can indicate whether a match was found or not
$matchFound = false;

// Now we loop through each entry in our arrays looking for a valid match
for ($count = 0; $count < count($usernames) && $matchFound == false; $count++) {

// If username and password matches entry...
if ($username == $usernames[$count] && $password == $passwords[$count]) {

// Get the user's message and indicate we've found a match
$message = $messages[$count];
$matchFound = true;
}
}

// If we found a match...
if ($matchFound) {

// Tell the Flash movie that login was successful and return custom message
print "&result=Okay&message=" . urlencode($message);
} else {

// Otherwise, tell Flash movie we failed
print "&result=Fail&errorMsg=" . urlencode("No match found for username/password");
}

?>




I'm attempting to recreate this in AS.

senocular
February 28th, 2005, 07:23 PM
I was talking about your AS version