Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-31-2009, 01:44 AM   #1
nbt9p54
Registered User
 
Join Date: Oct 2008
Posts: 9
Default How to generate a filelist

I'd like to have a directory on my web site which contains files that people could download. I'd like to use flex - for the learning experience as much as anything. I was thing of using FileReference to actually do the download but I do not know how to generate the list of files from within flex that I would include in a list for the user to pick from.

Looking for some pointers in some direction.
nbt9p54 is offline   Reply With Quote
Old 01-31-2009, 04:46 AM   #2
fx.barrett
Paintball Freak
 
fx.barrett's Avatar
 
Join Date: Jul 2008
Location: Romania, TM
Posts: 467
Send a message via MSN to fx.barrett Send a message via Skype™ to fx.barrett
Default

From what I know, Flex nor Flash can do such a generation by their own. You'll need a server-side language like PHP or ASP.NET to read the contents of your folder, generated an XML structure ( preferably ) out of the data you have just read and pass that to Flex.

Once you have the list and the paths to the files then you can use the FileReference class to handle the downloading process. I too am planning on doing something like this but for a File Uploader application where to users can visualize the files they just uploaded inside Flex and hopefully post the experiment with source code and everything on my blog so others can hopefully learn from it but I first have to make myself some free time...

Good luck mate.
__________________
FLASHFORUM.RO - You must speak Romanian in order to join.
BLOG.WISEBISOFT.COM - Share and Experiment.

Last edited by fx.barrett; 01-31-2009 at 04:49 AM.
fx.barrett is offline   Reply With Quote
Old 02-03-2009, 12:38 AM   #3
nbt9p54
Registered User
 
Join Date: Oct 2008
Posts: 9
Default i/o error 2038

I have made progress on this small project but still having what I think will be the last issue.

The flex app starts by using HTTPRequest to invoke a php script on the server side. The PHP gathers the name of all of the files in the directory and puts them into an XML file that is passed back to Flex. Flex then loads the XML into a datagrid where the user can select the file they wish to download.

I’m using FileReference to attempt doing the downloads and have incorporated the tutorial example from http://blog.flexexamples.com/2007/07...ference-class/ into my code.

The incorporated code works and the download is successful when I download the file that the author has in the example. However when I change to load a file from my web site the download starts but soon fails with an error 2038. It seems to me that there is something that prevents the download on my site. Here is the code.

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="init();" viewSourceURL="srcview/index.html">
	
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.collections.ArrayCollection;
			import flash.net.FileReference;

		
			
			[Bindable]
			private var arrColl:ArrayCollection;

			// URL of the file to download.
			private const FILE_URL:String = "http://localhost/alma1208/public_html/Download/FileReference_download_test.zip";

			private var fileRef:FileReference;
			private var urlReq:URLRequest;
			
			private function init():void {
				// Initialize the array collection to an empty collection.
				arrColl = new ArrayCollection();
				
				// Set up the URL request to download the file specified by the FILE_URL variable
				urlReq = new URLRequest(FILE_URL);
				
				// Define file reference object and add a bunch of event listeners.
				fileRef = new FileReference();
				fileRef.addEventListener(Event.CANCEL, doEvent);
				fileRef.addEventListener(Event.COMPLETE, doEvent);
				fileRef.addEventListener(Event.OPEN, doEvent);
				fileRef.addEventListener(Event.SELECT, doEvent);
				fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, doEvent);
				fileRef.addEventListener(IOErrorEvent.IO_ERROR, doEvent);
				fileRef.addEventListener(ProgressEvent.PROGRESS, doEvent);
				fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doEvent);
			}
			
			private function doEvent(evt:Event):void {
				// Create shortcut to the FileReference object.
				var fr:FileReference = evt.currentTarget as FileReference;
				
				// Add event order and type to the DataGrid control.
				arrColl.addItem({data:arrColl.length+1, type:evt.type, eventString:evt.toString()});

				try {
					// Update the Model.
					fileRefModel.creationDate = fr.creationDate;
					fileRefModel.creator = fr.creator;
					fileRefModel.modificationDate = fr.modificationDate;
					fileRefModel.name = fr.name;
					fileRefModel.size = fr.size;
					fileRefModel.type = fr.type;
					// Display the Text control.
					txt.visible = true;
				} catch (err:*) {
					// uh oh, an error of sorts.
				}
			}

			private function downloadSourceCodeZip():void {
				// Clear existing array collection.
				arrColl = new ArrayCollection();
				// Hide the Text control.
				txt.visible = false;
				// Begin download.
				fileRef.download(urlReq);
			}
			
			private function showAlert(item:Object):void {
				Alert.show(item.eventString, item.type);
			}
		]]>
	</mx:Script>
	
	<mx:Model id="fileRefModel">
		<file>
			<creationDate>{""}</creationDate>
			<creator>{""}</creator>
			<modificationDate>{""}</modificationDate>
			<name>{""}</name>
			<size>{""}</size>
			<type>{""}</type>
		</file>
	</mx:Model>
	
	<mx:Button id="downloadBtn" label="Download example source code"  click="downloadSourceCodeZip()" toolTip="{FILE_URL}" height="40" />

	<mx:DataGrid id="debug" dataProvider="{arrColl}" width="{downloadBtn.width}" rowCount="5" rowHeight="22" itemClick="showAlert(event.currentTarget.selectedItem)">
		<mx:columns>
			<mx:DataGridColumn dataField="data" headerText="#" width="20" />
			<mx:DataGridColumn dataField="type" headerText="Type" showDataTips="true" dataTipField="eventString" />
		</mx:columns>
	</mx:DataGrid>
	
	<mx:Text id="txt" condenseWhite="true" visible="false">
		<mx:text>
		creationDate: {fileRefModel.creationDate}
		creator: {fileRefModel.creator}
		modificationDate: {fileRefModel.modificationDate}
		name: {fileRefModel.name}
		size: {fileRefModel.size}
		type: {fileRefModel.type}
		</mx:text>
	</mx:Text>

</mx:Application>
nbt9p54 is offline   Reply With Quote
Old 02-03-2009, 07:56 AM   #4
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

What do you get if you try to navigate from the browser to the file you want to download?
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 02-03-2009, 08:05 AM   #5
fx.barrett
Paintball Freak
 
fx.barrett's Avatar
 
Join Date: Jul 2008
Location: Romania, TM
Posts: 467
Send a message via MSN to fx.barrett Send a message via Skype™ to fx.barrett
Default

Quote:
Originally Posted by wvxvw View Post
What do you get if you try to navigate from the browser to the file you want to download?
Maybe a custom window where to show the download progress...
I can't really think of anything else...
__________________
FLASHFORUM.RO - You must speak Romanian in order to join.
BLOG.WISEBISOFT.COM - Share and Experiment.
fx.barrett is offline   Reply With Quote
Old 02-03-2009, 08:41 AM   #6
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

Nope... actually you either have to get a system "save file" dialog, or IO (illegal operation) error telling that file cannot be found / downloaded for various reasons, like, for example, user needs to authentify / files are not accessible in that directory / wrong file name etc.
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 02-03-2009, 09:06 AM   #7
fx.barrett
Paintball Freak
 
fx.barrett's Avatar
 
Join Date: Jul 2008
Location: Romania, TM
Posts: 467
Send a message via MSN to fx.barrett Send a message via Skype™ to fx.barrett
Default

I think we weren't speaking the same language... I have to admit I didn't really read the first post and I only reacted to your post and then saw a file reference in his code and a spot where we was calling the "download" method... I thought that by your post you were referring to that... got me confused there...
__________________
FLASHFORUM.RO - You must speak Romanian in order to join.
BLOG.WISEBISOFT.COM - Share and Experiment.
fx.barrett is offline   Reply With Quote
Old 02-03-2009, 06:37 PM   #8
nbt9p54
Registered User
 
Join Date: Oct 2008
Posts: 9
Default More Detailed Info - Hopefully helpful

So when I download from the authors site successfully I see four items that the doEvent function has processed - select - open -progress - complete.

When I try to download from my web page I do get the file save dialogue box and in the doEvent function list I get the select but ioerror rather than open.

Does that shed any additional light on it for either of you?
nbt9p54 is offline   Reply With Quote
Old 02-03-2009, 06:46 PM   #9
nbt9p54
Registered User
 
Join Date: Oct 2008
Posts: 9
Default Think I found the problem

So my file directory was named Downloads rather than Download so of course it would never open. Thanks for the idea of using my own browser to look for the file - it became immediately noticeable what the problem was. Thanks to both of you. I have found this forum to be a source of valuable info. Hopefully I will soon be able to assist others rather than always asking.
nbt9p54 is offline   Reply With Quote
Reply


Thread Tools
Display Modes 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to generate Transparent png tarjinder80 AIR (Apollo) 0 09-04-2008 06:37 AM
dynamically generate multiple movie clips sleepydad ActionScript 2.0 5 01-24-2008 07:32 PM
How to Generate XML Document from Array Aollection? Pratap Flex 2, 3 & 4 1 01-10-2008 05:25 PM
SWF Generate SWF weilies ActionScript 2.0 1 03-22-2007 03:22 AM
Generate XML file from an HTML form using PHP? andrewf Server-Side Scripting 0 06-20-2005 05:15 PM


All times are GMT. The time now is 09:46 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.