<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical">
<mx:Script>
<![CDATA[
import flash.filesystem.File;
import flash.filesystem.FileStream;
import mx.collections.ArrayCollection;
/*
** array to store the image files
*/
private var images:Array = new Array();
/*
** array collection to create random ratings values
*/
[Bindable]
private var imageAC: ArrayCollection;
private var xml:String = "";
/**
Function: dirSelect
Description:
* Chooses the directory containing images
Parameters:
event:Event
Returns:
void
See Also:
none
Created:
Jed Schneider 2008/10/20
Modified:
$Id:$
*/
private function selectDir(event:Event):void
{
var file:File = new File();
file.addEventListener(Event.SELECT, dirSelectHandler);
file.browseForDirectory("Select the Image Folder");
}
/**
Function: dirSelectHandler
Description:
* Event fires when the selected directory containing images is returned.
* The directory structure is scanned for hidden files and hidden
* files are ingnored.
* For real image files (no file filtering here) a random number is generated
* between 25 and 100.
* The data is placed into the data grid and the graph is created with the values
* from the random number generation.
Parameters:
event:Event
Returns:
void
See Also:
selectDir
Created:
Jed Schneider 2008/10/20
Modified:
$Id:$
*/
private function dirSelectHandler(event:Event):void
{
trace(event.toString());
var selectedDir:File = new File(event.currentTarget.nativePath);
images = selectedDir.getDirectoryListing();
imageAC = new ArrayCollection();
for(var i:int=0; i<images.length; i++)
{
/*
** check to see if file is hidden by the file system
*/
if(!images[i].isHidden)
{
/*
** create random number
*/
var rand:int = new int;
rand = Math.random()*100;
if (rand<=25)
{
rand+=25;
}//end if
/*
** creating the array collection
** with evaluated values.
*/
imageAC.addItem({thumbnail:(images[i].name),
location:(images[i].nativePath),
imagePosition: (i),
attentionScore: (rand)});
}//end if
}//end for
imageAC.refresh();
barChart.dataProvider = imageAC;
}
/**
Function: writeXML
Description:
* creates a string that contains the output in XML.
Parameters:
none
Returns:
void
See Also:
none
Created:
Jed Schneider 2008/10/20
Modified:
$Id:$
*/
private function writeXML():void
{
//xml encoding
xml += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "\n";
//header comment section
xml += "<!--" + "\n"
+ "****************************************************************************************************" + "\n"
+ "**" + "\n"
+ "**" + "\n"
+ "**" + "\t" + "File Name: " + "attention.xml" + "\n"
+ "**" + "\t" + "Project Description" + " Project Settings XML file" + "\n"
+ "**" + "\n"
+ "**" + "\n"
+ "****************************************************************************************************"
+ "-->"
+ "\n" + "\n" ;
//root open tag
xml += "<attention>" + "\n";
//individual tags
for (var i:int=0; i<imageAC.length; i++)
{
xml += "\t" + "<score>" + "\n";
xml += "\t\t" + "<imagePosition>" + "\n";
xml += "\t\t\t" + imageAC[i].imagePosition + "\n";
xml += "\t\t" + "</imagePosition>" + "\n";
xml += "\t\t" + "<atScore>" + "\n";
xml += "\t\t\t" + imageAC[i].attentionScore + "\n";
xml += "\t\t" + "</atScore>" + "\n";
xml += "\t" + "</score>" + "\n";
}//end for
//root close tag
xml += "</attention>";
}
/**
Function: saveToFile
Description:
* Saves the xml string to an xml file named attention.xml on the desktop.
Parameters:
none
Returns:
void
See Also:
none
Created:
Jed Schneider 2008/10/20
Modified:
$Id:$
*/
private function saveToFile():void
{
writeXML();
trace(xml);
var xmlFile:File = File.desktopDirectory.resolvePath("attention.xml");
var fs:FileStream = new FileStream();
fs.open(xmlFile, FileMode.WRITE);
fs.writeUTFBytes(xml);
fs.close();
}
]]>
</mx:Script>
<mx:HBox>
<mx:Button
id="btnGetFolder"
label="Select Folder"
click="selectDir(event)"
/>
<mx:Button
id="btnSave"
label="Save to XML"
click="saveToFile()"
/>
</mx:HBox>
<mx:VDividedBox>
<mx:Panel
width="100%">
<mx:AdvancedDataGrid
id="grid"
dataProvider="{imageAC}"
width="100%"
height="100%">
<mx:columns>
<mx:AdvancedDataGridColumn
dataField="thumbnail"/>
<mx:AdvancedDataGridColumn
dataField="location"/>
<mx:AdvancedDataGridColumn
dataField="attentionScore" />
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Panel>
<mx:Panel>
<mx:BarChart
id="barChart">
<mx:verticalAxis>
<mx:CategoryAxis categoryField="imagePosition"/>
</mx:verticalAxis>
<mx:series>
<mx:BarSeries
yField="imagePosition"
xField="attentionScore"
displayName="Attention Score"
/>
</mx:series>
</mx:BarChart>
</mx:Panel>
</mx:VDividedBox>
</mx:WindowedApplication>