A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: If statements that load Text according to the Day of the week..

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    1

    If statements that load Text according to the Day of the week..

    I am so stuck on this. I have never worked with Dates/Days in AS3 and I cannot figure this out.

    What I need is a code that pulls up different .txt files depending on what day of the week it is. So...If it's Monday it loads Monday.txt, if it's Tuesday it loads Tuesday.txt and so on.

    In case it matters I'm working in Flash CS4 and AS3. Using this code for a site for a friends bar, they have daily specials that change almost every week. So I want him to be able to change the text with out involving me. Hence the .txt files...and he thought it would be cool to have it on the home page saying "Hey it's Monday come in during Happy hour for $2 tequila shots"

    Any helps or pointers would be awesome!

    Cheers!

  2. #2
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Here is some code to get you started.

    Code:
    //Array to hold message days
    var dayMessages:Array = new Array();
    dayMessages[0] = 'This is Sunday message';
    dayMessages[1] = 'This is Monday message';
    dayMessages[2] = 'This is Tuesday message';
    dayMessages[3] = 'This is Wednesday message';
    dayMessages[4] = 'This is Thursday message';
    dayMessages[5] = 'This is Friday message';
    dayMessages[6] = 'This is saturday message';
    
    
    //Function to display message
    function showDayMessage():void
    {
    	var d:Date = new Date();
    	var tf:TextField = new TextField();
    	addChild(tf);
    
    	switch(d.getDay())
    	{
    		case 0:
    			trace('Sunday');
    			tf.text = dayMessages[0];
    		break;
    		
    		case 1:
    			trace('Monday');
    			tf.text = dayMessages[1];
    		break;
    		
    		case 2:
    			trace('Tuesday');
    			tf.text = dayMessages[2];
    		break;
    		
    		case 3:
    			trace('Wednesday');
    			tf.text = dayMessages[3];
    		break;
    		
    		case 4:
    			trace('Thursday');
    			tf.text = dayMessages[4];
    		break;
    		
    		case 5:
    			trace('Friday');
    			tf.text = dayMessages[5];
    		break;
    		
    		case 6:
    			trace('Saturday');
    			tf.text = dayMessages[6];
    		break;
    	}
    }
    
    
    showDayMessage();

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center