Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2008
    Posts
    235
    Thanks
    6
    Thanked 21 Times in 20 Posts

    trace returning undefined when it shouldn't! :(

    http://pastebin.com/d40bbeeb4

    Can u have a look the trace(SelectedDate.indexOf(CurrentDate.dat)); returns 'undefined' any ideas why?

    I did the pastebin for easier reading here is the code as well:

    Code:
    on (release) {
    	
    	var SelectedDate:String 
    	SelectedDate = MyCalendar.selectedDate;
    	
    	var DateArray:Array = new Array();
    	DateArray.push({dat:"Apr 8", details:"Some event here..."});
    	DateArray.push({dat:"Apr 9", details:"Some event here..."});
    	DateArray.push({dat:"Apr 10", details:"Some event here..."});
    	DateArray.push({dat:"Apr 11", details:"Some event here..."});
    	DateArray.push({dat:"Apr 12", details:"Some event here..."});
    	
    	//set wether a result has been found to no as default
    	var Found:Boolean;
    	Found = false;
    	//the var used for looping through the array
    	var Count:Number;
    	Count = 0;
    	
    	//beginning of array loop through
    	while (DateArray[Count]) {
    			
    		CurrentDate = DateArray[Count];
    		var TheDate:String;
    		var TheSelection:String;
    		TheDate = CurrentDate.dat;
    		TheSelection = SelectedDate;
    		
    		trace(SelectedDate.indexOf(CurrentDate.dat));
    		if (SelectedDate.indexOf(CurrentDate.dat) > -1) {
    			var Result:String;
    			Result = CurrentDate.dat + ":\n" + CurrentDate.details;
    			Found = true;
    		}
    		Count++;
    	}
    	if (Found == true) {
    		infoLabel.text = Result;
    	}
    	if (Found == false) {
    		infoLabel.text = "Sorry:\n- Nothing was found for this date.";
    	}	
    }
    Andrew Sharman
    Web designer, developer and programmer.

    If you found my post helpful, why not give thanks! :)

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    indexOf works only with Strings, not Arrays. So perhaps try

    Code:
    trace(SelectedDate.indexOf(TheDate));
    since it would have already been extracted to this variable.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    New Coder
    Join Date
    Apr 2008
    Location
    Makati Philippines
    Posts
    34
    Thanks
    0
    Thanked 1 Time in 1 Post
    if solution above did not work try this...

    Code:
    trace(TheSelection.indexOf(TheDate));
    Hope is a good thing, maybe the best of things. And no good thing ever dies. -Andy Dufresne

    Jairus Bondoc PHP Programmer Philippines


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •