Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

How to load a text file with Flash CS3

This is a discussion on How to load a text file with Flash CS3 within the Tutorials forums, part of the Flash English category; Wo wo wooo Here we are with a new article to add to the series on how to load external ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  3 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 23-09-07, 19:50
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
How to load a text file with Flash CS3

Wo wo wooo

Here we are with a new article to add to the series on how to load external files with Flash CS3.
We saw how to communicate with a PHP file   and how to integrate PHP and mySQL to Flash CS3
Now we will see how to load an external text file and display it in Flash CS3.
I would like to precise that this article is only educative and that I stick to the idea that to load external data, the best way is using an XML file.

Anyway…let us get into it… I create a FLA and save it as ‘file_di_testo.fla’.
I create a Document Class, an AS file saved as ‘Main.as’, implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IEventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLVariables;
	import flash.net.URLRequest;
	
	public class Main extends MovieClip
	{
		public function Main()
		{
			inviaDati();
		}
		
		private function addListeners(d:IEventDispatcher):void
		{
			d.addEventListener(Event.COMPLETE,completato);
		}
		
		private function completato(e:Event):void
		{
			var loader:URLLoader=URLLoader(e.target);
			var vars:URLVariables=new URLVariables(loader.data);
			trace(vars.nome);
		}
		
		private function inviaDati():void
		{
			var richiesta:URLRequest=new URLRequest();
			richiesta.url='http://www.flepstudio.org/swf/pippo.txt';
			var loader:URLLoader=new URLLoader();
			addListeners(loader);
			try 
			{
				loader.load(richiesta);
			} 
			catch (error:Error) 
			{
				trace('Non è stato possibile caricare il documento');
			}
		}
	}
}
The text file is named as ‘pippo.txt’, into which I have this simple declaration:
nome=filippo

Let us analyse the code

Constructor function
public function Main()
{
I call the method inviaDati();
inviaDati();
}

Methods
inviaDati();
I ask Flash to do an URL request using the URLRequest Class
var richiesta:URLRequest=new URLRequest();
I assign the path to the text file as the property of the URL request
richiesta.url='http://www.flepstudio.org/swf/pippo.txt';
I create an URLLoader
var loader:URLLoader=new URLLoader();
I call the method addListeners and load the text file using the method load of the Loader Class.
If the call to the file is incorrect, I do a trace which returns a message of error
addListeners(loader);
try
{
loader.load(richiesta);
}
catch (error:Error)
{
trace('Non è stato possibile caricare il documento');
}

addListeners();
I add a listener to follow the file’s loading phase. In this case, we only need it to know when the file has been loaded completely
d.addEventListener(Event.COMPLETE,completato);

completato();
I create a Loader to be able to retrieve the data from the uploaded file. In fact, I pass as a parameter the first URLLoader which has done the call
var loader:URLLoader=URLLoader(e.target);
I create an instance of the URLVariables Class to which I pass as parameter the data of the new URLLoader
var vars:URLVariables=new URLVariables(loader.data);
I retrieve the data, calling ‘nome’ (name of the variable included in the text file) as a property of URLVariables
trace(vars.nome);

Stay tuned !
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 26-12-07, 08:01
Junior Member
 
Join Date: Oct 2007
Posts: 15
Rep Power: 0
getosled is on a distinguished road
Re: How to load a text file with Flash CS3

Flep could you explain in a little more detail how to do this and possibly with out making a document class, im still learning and the document classes are still a bit confusing to me. All I want to do is leave a .txt document on my server and update that which should auto update my flash movie.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 26-12-07, 08:10
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Re: How to load a text file with Flash CS3

Hi

You need PHP to update the txt file.
Flash can't write files.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 26-12-07, 10:13
Junior Member
 
Join Date: Oct 2007
Posts: 15
Rep Power: 0
getosled is on a distinguished road
Re: How to load a text file with Flash CS3

Flep,
ill physically go in and change the .txt file. I use to know how to do it under Flash 2.0

I just want CS3 to load the document in a dynamic text field. Ill change the document ever now and then.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 26-12-07, 10:15
Junior Member
 
Join Date: Oct 2007
Posts: 15
Rep Power: 0
getosled is on a distinguished road
Re: How to load a text file with Flash CS3

I use to use a notepad file and loaded it into a dynamic text field, thats what i want to try to do again but in CS3 now.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 26-12-07, 15:54
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Re: How to load a text file with Flash CS3

Hi,
without Document Class:

Code:
loadFile();

function loadFile():void
{
	var request:URLRequest=new URLRequest();
	request.url='http://www.flepstudio.org/swf/pippo.txt';
	var loader:URLLoader=new URLLoader();
	addListeners(loader);
	try 
	{
		loader.load(request);
	} 
	catch (error:Error) 
	{
		trace('Non è stato possibile caricare il documento');
	}
}

function addListeners(d:IEventDispatcher):void
{
	d.addEventListener(Event.COMPLETE,onComplete);
}
		
function onComplete(e:Event):void
{
	var loader:URLLoader=URLLoader(e.target);
	var vars:URLVariables=new URLVariables(loader.data);
	trace(vars.nome);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 27-12-07, 07:52
Junior Member
 
Join Date: Oct 2007
Posts: 15
Rep Power: 0
getosled is on a distinguished road
Re: How to load a text file with Flash CS3

You are the man Flep.. Is there any guide to learning about document classes? I notice alot of flash is done with a document class, but im having a hard time with AS 3.0 as it is much less trying to learn how to do a document class.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 27-12-07, 09:13
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Re: How to load a text file with Flash CS3

Quote:
Originally Posted by getosled View Post
You are the man Flep.. Is there any guide to learning about document classes? I notice alot of flash is done with a document class, but im having a hard time with AS 3.0 as it is much less trying to learn how to do a document class.
1)
The Document Class of Flash CS3

2)
Call from the timeline to the Document Class and vice versa with Flash CS3

3)
http://www.flepstudio.org/forum/obje...ing-tutorials/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 23-01-08, 11:25
Junior Member
 
Join Date: Jan 2008
Posts: 1
Rep Power: 0
JAYCO is on a distinguished road
Re: How to load a text file with Flash CS3

This looks good.

However, instead of trace the contents of the text file, i want to dispay it into a textfield or a text area. What additional programming is necessary?

Thank You
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 25-01-08, 09:16
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Re: How to load a text file with Flash CS3

Hi JAYCO and welcome

You just need to add the value at a TextField.
my_txt.text=vars.nome;
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
salvare file xml.... da flash edo_flash Off Topic - Libera la mente 1 02-12-08 13:53
pagina asp dentro text flash? mogepa CSS | HTML 2 13-10-08 17:18
Actionscript 2 Load css in flash... rickymas Flash Italiano 2 30-09-08 22:15
loading external text file in nested flash file angel3m HELP free utilities 0 16-07-08 22:18
why can't i post html in my flash text???? roxylady HELP free utilities 3 26-04-08 02:51


All times are GMT. The time now is 18:28.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap