Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2011, 01:18 AM   PM User | #1
sparekey
New to the CF scene

 
Join Date: Jul 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
sparekey is an unknown quantity at this point
How to create datagrid from xml that changes depending on the day in flash builder 4

I have a datagrid in Flash Builder 4 that is successfully linked to an xml file. However, I need it to display different data from that same xml file depending of the day of week it is.

The xml is structured as follows.
Code:
<database>
	<eatery>
		<name>UT</name>
			<open>
				<sunday>1100</sunday>
				<monday>1030</monday>
				<tuesday>1030</tuesday>
				<wednesday>1030</wednesday>
				<thursday>1030</thursday>
				<friday>1030</friday>
				<saturday>1100</saturday>
			</open>
			<close>
				<sunday>2000</sunday>
				<monday>2100</monday>
				<tuesday>2100</tuesday>
				<wednesday>2100</wednesday>
				<thursday>2100</thursday>
				<friday>2100</friday>
				<saturday>2100</saturday>
			</close>
	</eatery>
</database>
I want my datagrid to display the correct open and close times for only the current day.

I know how to find the date I just don't understand where I would go about writing an if else statement or such, or how to get the open and close data to change in my data grid.

I haven't been able to find an answer to this so if anyone could show me how to do this or point me somewhere that explains this I would greatly appreciate it!

Last edited by sparekey; 07-18-2011 at 07:30 PM..
sparekey is offline   Reply With Quote
Old 07-17-2011, 07:39 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Something like this should work for you:
Code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   minWidth="500" minHeight="500"
			   creationComplete="application1_creationCompleteHandler(event)">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
		<fx:XML id="db">
			<database>
				<eatery>
					<name>UT</name>
					<open>
						<sunday>1100</sunday>
						<monday>1030</monday>
						<tuesday>1030</tuesday>
						<wednesday>1030</wednesday>
						<thursday>1030</thursday>
						<friday>1030</friday>
						<saturday>1100</saturday>
					</open>
					<close>
						<sunday>2000</sunday>
						<monday>2100</monday>
						<tuesday>2100</tuesday>
						<wednesday>2100</wednesday>
						<thursday>2100</thursday>
						<friday>2100</friday>
						<saturday>2100</saturday>
					</close>
				</eatery>
			</database>
		</fx:XML>
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import mx.collections.XMLListCollection;
			import mx.events.FlexEvent;

			[Bindable]
			private var day:String = '';
			
			private var weekDayLabels:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
			
			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				day = weekDayLabels[new Date().getDay()].toString().toLowerCase();
			}
			
		]]>
	</fx:Script>
	
	<s:DataGrid x="0" y="80" width="490" height="411" dataProvider="{new XMLListCollection(db.eatery)}">
		<s:columns>
			<s:ArrayList>
				<s:GridColumn dataField="name" headerText="Name"></s:GridColumn>
				<s:GridColumn dataField="open.{day}" headerText="Open"></s:GridColumn>
				<s:GridColumn dataField="close.{day}" headerText="Close"></s:GridColumn>
			</s:ArrayList>
		</s:columns>
	</s:DataGrid>
	<s:Label x="10" y="10" width="199" height="26" text="Day of week: {day}"/>
</s:Application>
Compiled against Flex 4.5.1.
Inigoesdr is offline   Reply With Quote
Users who have thanked Inigoesdr for this post:
sparekey (07-18-2011)
Old 07-18-2011, 07:34 PM   PM User | #3
sparekey
New to the CF scene

 
Join Date: Jul 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
sparekey is an unknown quantity at this point
I guess the part that I really didn't know that was possible was using .{day} in the dataField. I'm new to actionscript and was completely stuck on this. Thanks for helping out!
sparekey is offline   Reply With Quote
Reply

Bookmarks

Tags
actionscript, change, datagrid, flex, xml

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:29 AM.


Advertisement
Log in to turn off these ads.