943,625 Members | Top Members by Rank

Ad:
Aug 9th, 2009
0

ActionScript 3 help ! : )

Expand Post »
Hola, Im an experienced coder, however new to java/actionscript 3

I am trying to make a very simple login and I am running into problems. They seem to be with my for loop with the .Length() function in particular...

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. stop();
  2. loginError.visible = false;
  3. var loginXml:XML;
  4. var loader:URLLoader = new URLLoader();
  5. loader.load(new URLRequest("logindata.xml"));
  6. loader.addEventListener(Event.COMPLETE, loadXML);
  7. var loginData = new Array();
  8. var temp:Array = new Array();
  9. function loadXML(e:Event):void
  10. {
  11. loginXml = new XML(e.target.data);
  12. var total = loginXml.item.length();
  13. var x:int = 0;
  14. for(x=0; x < total; x++)
  15. {
  16. loginData[x] = new Array();
  17. loginData[x][0] = loginXml.item[x].user.toString();
  18. loginData[x][1] = loginXml.item[x].pass.toString();
  19. }
  20.  
  21. }
  22. loginBtn.addEventListener(MouseEvent.CLICK, loginFunction2);
  23.  
  24. function loginFunction2(e:MouseEvent):void
  25. {
  26. var success:Boolean = false;
  27. //SEEMS TO BE WHERE MY ERROR STARTS
  28. var lengthLD:int = loginData.length();
  29. for(var i=0; i < lengthLD; i++) //Most Likley the Error
  30. {
  31. if(user.text == loginData[i][0] && pass.text == loginData[i][1])
  32. {
  33. success = true;
  34. gotoAndStop(user.text);
  35. }
  36. }
  37. if(!success)
  38. {
  39. loginError.visible = true;
  40. }
  41. }


Any help would be great,
Thanks : )
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
DevC++4.9.9.2 is offline Offline
39 posts
since Apr 2008
Aug 10th, 2009
0

Re: ActionScript 3 help ! : )

I'd just make a global variable

var loginXml:XML;
var loader:URLLoader = new URLLoader(); 
loader.load(new URLRequest("logindata.xml"));
loader.addEventListener(Event.COMPLETE, loadXML);
var loginData = new Array();
var temp:Array = new Array();


var gtotal:int = 0;

function loadXML(e:Event):void
{
    loginXml = new XML(e.target.data);
	gtotal = loginXml.item.length();	
                var x:int = 0;
	for(x=0; x < gtotal; x++)
	{
		loginData[x] = new Array();
		loginData[x][0] = loginXml.item[x].user.toString();
		loginData[x][1] = loginXml.item[x].pass.toString();
		
		//trace it out
		//trace(loginData[x][1]);
		
		
	}
	
	//trace(gtotal);
	
}

button1.addEventListener(MouseEvent.CLICK, go);
function go(e:MouseEvent)
{
  var success:Boolean = false;

   
	for(var i=0; i < gtotal; i++)                   //Most Likley the Error
	{
		if(user.text == loginData[i][0] && pass.text == loginData[i][1])
		  {
			  success = true;
			  //gotoAndStop(user.text);
		  }
	}
	if(!success)
	{
		//loginError.visible = true;
	}
	
	trace(success);

}


my xml file:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. <root>
  2. <item>
  3. <user>john</user>
  4. <pass>password</pass>
  5. </item>
  6. <item>
  7. <user>sally</user>
  8. <pass>hello</pass>
  9. </item>
  10. </root>
Last edited by iamthwee; Aug 10th, 2009 at 6:18 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 10th, 2009
0

Re: ActionScript 3 help ! : )

In AS 3.0, its very simple to find the length.

Step 1:

Use this:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. var loginform:XMLList;
  2. var total:Number=0;

instead of :

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. var gtotal:int = 0;


Step 2:

use this:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. total = loginform.length();

instead of:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. gtotal = loginXml.item.length();


Sure It will work, if yes, mark as solved. Thanks
Reputation Points: 167
Solved Threads: 239
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,445 posts
since May 2008
Aug 10th, 2009
0

Re: ActionScript 3 help ! : )

I looked into your code and executed the half, but your method of total is perfectly working.
Reputation Points: 167
Solved Threads: 239
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,445 posts
since May 2008
Aug 10th, 2009
3

Re: ActionScript 3 help ! : )

Mr. DevC++4.9.9.2,

I am so sorry I am confused forget all those things said above, that is also correct, but in your program nothing is wrong except you have to remove two parenthesis in length function, thats it done.

var lengthLD:int = loginData.length;
Reputation Points: 167
Solved Threads: 239
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,445 posts
since May 2008
Aug 10th, 2009
0

Re: ActionScript 3 help ! : )

Yep post #5 was the correct answer, or should I say the shortest answer/fix.
Last edited by iamthwee; Aug 10th, 2009 at 8:26 am.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 10th, 2009
0

Re: ActionScript 3 help ! : )

Thank you very much... This answer worked... I am coming from c++ and these little things are ganna kill me lol

My final code:
Graphics and Multimedia Syntax (Toggle Plain Text)
  1. stop();
  2. loginError.visible = false;
  3. var loginXml:XML;
  4. var loader:URLLoader = new URLLoader();
  5. loader.load(new URLRequest("logindata.xml"));
  6. loader.addEventListener(Event.COMPLETE, loadXML);
  7. var loginUser:Array = new Array();
  8. var loginPass:Array = new Array();
  9. var total:Number = 0;
  10. function loadXML(e:Event):void
  11. {
  12. loginXml = new XML(e.target.data);
  13. total = loginXml.length();
  14. var x:Number = 0;
  15. for(x=0; x < total; x++)
  16. {
  17. loginUser.push(loginXml.item[x].user.toString());
  18. loginPass.push(loginXml.item[x].pass.toString());
  19. }
  20. }
  21. loginBtn.addEventListener(MouseEvent.CLICK, loginFunction);
  22.  
  23. function loginFunction(e:MouseEvent):void
  24. {
  25. var success:Boolean = false;
  26. var i:Number = 0;
  27. for(i=0; i < total; i++)
  28. {
  29. if(user.text == loginUser[i] && pass.text == loginPass[i])
  30. {
  31. success = true;
  32. gotoAndStop(user.text);
  33. }
  34. }
  35. if(!success)
  36. {
  37. loginError.visible = true;
  38. }
  39. }


thanks again

In AS 3.0, its very simple to find the length.

Step 1:

Use this:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. var loginform:XMLList;
  2. var total:Number=0;

instead of :

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. var gtotal:int = 0;


Step 2:

use this:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. total = loginform.length();

instead of:

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. gtotal = loginXml.item.length();


Sure It will work, if yes, mark as solved. Thanks
Reputation Points: 10
Solved Threads: 1
Light Poster
DevC++4.9.9.2 is offline Offline
39 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Graphics and Multimedia Forum Timeline: Need help coverting PSD to .gif transparent
Next Thread in Graphics and Multimedia Forum Timeline: flash Water Segment





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC