Array and Loop problems (Please Help)

FLASH

    Next

  • 1. Password Protected Page
    Basically, i have a page on my flash site that i want to be password protected. I want the user to have to put in forty or 40 as the password and then click the graphic of the lock in the center of the page for it to continue on with the content. So far i have the page with an input box labeled password to put the password in, and the lock button graphic in the center. The frame after the one the page makes you stop on to input the password is named invalid. The frames after the invalid frames are labeled correct. If the user puts in the wrong password i want it to go to the invalid frames after clicking the lock. If the user puts in 40 or forty as the password, i want it to go to the correct frames. The code i have now on the lock is as follows: on (press) { if (password= "forty") { gotoAndPlay("correct"); } else { gotoAndStop("incorrect"); } } But it doesn't seem to work... Any help would be much appreciated. Also, if you can tell me how I can make it so the text typed in the input box is all in *'s like most sites that would be amazing. Thanks again
  • 2. Linking an email using the getURL action
    I am trying to figure out if it is possible to add a subject line to an email setup using the getURL action? Say I have a flash site setup with two sections. One section has all the information you would want to know about apples and the other section has all the information you would want to know about oranges. In both of these sections I have a preaddressed email link setup so that a user could email me with a question about either apples or oranges. What I want to do is add a subject line to the preaddressed email so that when I recieve the emails I know whether it concerns apples or oranges. If you have any info about this subject it would greatly be appreciated. Thank you. Helplessly Hoping in Maryland
  • 3. Dynamic Text with Several colors
    Is it possible to specify specific parts of an external .txt file that loads into a dynamic text field to be different colors?
  • 4. loadMovieNum target layers question
    Is this: loadMovieNum("my.swf", "_self", "GET"); and this: loadMovieNum("my.swf", 0, "GET"); the same? assuming that this is the only mc playing, and it's on the default level? What are the risks of using one over the other?

Array and Loop problems (Please Help)

Postby Hadgy » Wed, 13 Jun 2007 15:31:19 GMT

Im making a website for a project where i have to include an Array and a Loop.

 To pass this section i have put in a "Contact Us/Q and A" page where the user 
can enter in a name, email, and question.
 That information gets sent to an array and then next frame displays the form 
information from the array in dynamic text boxes.

 I have included a For Loop to check that each part of the array contains data 
(name, email and question).
 Then i have an If Else which will either clear the form if a section was 
missed out, OR if the form was completely properly it takes the user to the 
next frame where as i said above the details are displayed in dynamic text 
boxes.

 The problem im having is the For Loop to check the array is messing it up. Can 
someone please help me out here and get the For Loop to check that the all 
fields have been filled in.

 Here is my code for the initial frame



 stop();
 var contact:Array = new Array(tiName.text, tiEmail.text, tiQuestion.text);
 name = contact[0];
 email = contact[1];
 question = contact[2];
 btSubmit.onRelease = function() {
 	trace(contact);
 	gotoAndStop(30);
 };

 //HERE IS MY CODE FOR THE NEXT FRAME (30)
 for (i=0; i<3; i++) {
 	if (contact[i] == "") {
 		gotoAndStop(29);
 	} else {
 		outputName = name;
 		outputEmail = email;
 		outputQuestion = question;
 	}
 }


Re: Array and Loop problems (Please Help)

Postby GWD » Wed, 13 Jun 2007 16:04:05 GMT

You need to update the values in your array at the time the submit button is 
pressed. Code follows

 There's a second example for checking the strings (its kinda complicated, but 
its a useful trick if you can understand it). This doesn't let the submit 
button work unless all fields have something in them





 stop();
 var contact:Array = [];
 var name:String = "";
 var email:String = "";
 var question:String = "";
 //
 btSubmit.onRelease = function() {
 	contact = new Array(tiName.text, tiEmail.text, tiQuestion.text);
 	name = contact[0];
 	email = contact[1];
 	question = contact[2];
 	trace(contact);
 	gotoAndStop(30);
 };

 //HERE IS MY CODE FOR THE NEXT FRAME (30)
 for (i=0; i<3; i++) {
 	if (contact[i] == "") {
 		gotoAndStop(29);
 	} else {
 		outputName = name;
 		outputEmail = email;
 		outputQuestion = question;
 	}
 }


 //or you could do it like this:
 stop();
 var contact:Array = [];
 var name:String = "";
 var email:String = "";
 var question:String = "";
 //
 btSubmit.onRelease = function() {
 	contact = new Array(tiName.text, tiEmail.text, tiQuestion.text);
 	name = contact[0];
 	email = contact[1];
 	question = contact[2];
 	//all this does is check there are no empty strings.. _marker_ could be 
anything that
 	//won't actually appear in any of the strings
 	if ((contact.join("_marker_")+"_marker_").indexOf("_marker__marker_") == -1) {
 		gotoAndStop(30);
 	}
 };


 //FRAME (30)
 outputName = name;
 outputEmail = email;
 outputQuestion = question;


Re: Array and Loop problems (Please Help)

Postby Hadgy » Wed, 13 Jun 2007 16:10:49 GMT

Thankyou so much, it works however it still proceeds to frame 30 even if nothing is entered into the question field

Re: Array and Loop problems (Please Help)

Postby GWD » Wed, 13 Jun 2007 16:38:37 GMT

Sorry - I see what you mean... I tried to adapt a technique I use for quickly 
finding if an array contains a string somewhere in its elements, but its not 
good for empty strings. This only finds them if there are two consecutive ones. 
Sorry I should have tested it first. 
 Well you can still do the loop test . You can also do this in the onRelease 
handler for the button on frame 29 to avoid sending the playhead forwards and 
backwards for invalid input.


Re: Array and Loop problems (Please Help)

Postby Hadgy » Wed, 13 Jun 2007 16:44:28 GMT

Ok i should be able to get it working, thanks again for your help, it was 
stressing me out all day cos it was one of the last things i had to finish off. 
 That time of year where all the projects are due at once AHHHH!

 Cheers again GWD


Re: Array and Loop problems (Please Help)

Postby GWD » Wed, 13 Jun 2007 16:48:32 GMT

I think this fixes it.

 btSubmit.onRelease = function() {
 	contact = new Array(tiName.text, tiEmail.text, tiQuestion.text);
 	name = contact[0];
 	email = contact[1];
 	question = contact[2];
 	//all this does is check there are no empty strings.. _marker_ could be 
anything that
 	//won't actually appear in any of the strings
 	checkString= "_marker_"+contact.join("_marker_")+"_marker_"
 	if (checkString.indexOf("_marker__marker_") == -1) {
 		gotoAndStop(30);
 	}
 };


Re: Array and Loop problems (Please Help)

Postby GWD » Wed, 13 Jun 2007 16:50:03 GMT

You're welcome. Good luck with it

Similar Threads:

1.Please help - printing arrays problem

Please help - i am currently loading data from a text file into flash using an 
array and loadVars......however when the data is loaded into the text box in 
flash there is a comma after it.......i tried using 'join()' but that didnt 
seem to work :( it just meant my variable was undefined. So any suggestions on 
how to delete commas from returned arrays would be great :)

 Thanks

 Jude

2.Please Help Xml to array problem

3.loop through array to build a new array

If I combine the following 2 functions (accesses by clicking a checkbox), as 
result the new array does not contains all items that matches the checkboxes I 
selected.


 private function clickHandler(event:Event):void
         {        		
 			
 			//Empty filtered array
 			selectedOffers.removeAll();
 			var selCheckbox:CheckBox = CheckBox(event.target);
             selCheckboxName = selCheckbox.id;
             selCheckboxName = selCheckboxName.substring(1);
             // If a checkbox has been selected, we add the corresponding 
categoryId to the selectedCategories array.
             selCatId = selCheckbox.id.substring(1);
             if (selCheckbox.selected){selectedCategories.addItem(selCatId);}
             else {
 	            // If a checkbox has been unselected, we remove it from the 
selectedCategories array.
                 var l:int = selectedCategories.length;
                 for (var i:int; i < l; i++)
                 {
                     if (selectedCategories.getItemAt(i) == selCatId)
                     {
                         selectedCategories.removeItemAt(i);
                         break;
                     }
                 }
             }
 						if(selectedCategories.length > 0)
 						{
 							//Call Category filter
 							getOffersByCategories(selectedCategories);
 						}
 						else
 						{
 							selectAll();
 						}
         }
         
         
         private function getOffersByCategories(selCats:ArrayCollection):void
         {
 			var iC:int;
 			var iSO:int;
 			while (iC <= selCats.length)
 			{
 		        while (iSO < Offers.length)
 				{
 					if(Offers[iSO].categories.search(selCats[iC]) != -1)
 	        	    {
 						selectedOffers.addItem(Offers[iSO]);
 						
 	            	}
 					iSO++;
 				}
 				iC++;
 			}
 			grdOffers.dataProvider = selectedOffers;
 		}

4.array and for loop problem

i'm trying to apply the same transition (currently on one frame of the 
timeline) to several images on individual frames. it was suggested earlier to 
use an array of all my mc instance names and apply a for loop.
 i've attached the code, but it seems to only work on the frame in which it 
sits.
 just wondering if there is something missing in the code that would apply it 
to all images.
 thanks in advance.



 import mx.transitions.Tween;
 import mx.transitions.easing;

 var mcNames:Array = new Array(adv1_mc, adv2_mc, adv3_mc, adv4_mc, adv5_mc, 
adv6_mc, adv7_mc, adv8_mc, adv9_mc, adv10_mc, adv11_mc, adv12_mc, adv13_mc, 
adv14_mc, adv15_mc, adv16_mc, adv17_mc, adv18_mc, adv19_mc, adv20_mc, adv21_mc, 
adv22_mc, adv23_mc, adv24_mc, adv25_mc, adv26_mc, adv27_mc, adv28_mc, adv29_mc);

 for(var i = 0; i<mcNames.length; i++){
       var t:Tween = new Tween(mcNames[i], "_alpha", Strong.easeIn, 0, 100, 1, 
true);
 };

5.Problems with looping in array

I've created a dropdown list clip that loads list items based on an array. The 
list items would link to external swf's and play them on the stage. However, as 
usual, I've run into a wall. 
 The list populates properly with the list item clips showing up tagged with 
the correct labels, but the URL is jacked up. In the snippet of code below 
there is a 'while' loop that creates the list items. Within that loop, I'm 
trying to create a URL string based on the same array item that is working 
perfectly well in creating and labeling the list items - buttonNames.
 However, when it comes to creating the URL, buttonNames returns the last item 
in the array for ALL of the list items. So, for example, I have a link that 
says 'Malaysia' but points to 'Other3.'
 What am I not getting?

 ---------------------------------------------

 var buttonNames:Array = ["Malaysia", "Other", "Other2", "Other3"];
 function populateList() {
 	menuDown += 1;
 	var spacing:Number = dropdownSlides.listItem._height+2;
 	var numberOfButtons:Number = buttonNames.length;
 	var i:Number = -1;
 	var origxItem:Number = dropdownSlides.listItem._x;
 	var origyItem:Number = dropdownSlides.listItem._y;
 	while (++i<numberOfButtons) {
 		var name:String = "listItem"+i;
 		dropdownSlides.listItem.duplicateMovieClip(name, i);
 		dropdownSlides[name]._visible = true;
 		dropdownSlides[name].listText.text = buttonNames;
 		dropdownSlides[name]._x = origxItem;
 		dropdownSlides[name]._y = origyItem-(i*spacing);
 		dropdownSlides._y += 22;
 		dropdownSlides[name].clipID = buttonNames;
 		var movieURL:String = buttonNames+".swf";
 		dropdownSlides[name].listButton.onRelease = function() {
 			_root.ssPlaceHolder._visible = true;
 			loadMovie(movieURL, "ssPlaceHolder");
 			closeMenu();
 		};

 
--------------------------------------------------------------------------------
-----------------------------

6. Mutidimensional Array and FOR Loop problem

7. problem looping static array in a class

8. please please please please please help!!!!



Return to FLASH

 

Who is online

Users browsing this forum: No registered users and 99 guest