As you all might have noticed, lately I have converted to actionscript 3.0 instead of the old actionscripting, and yes as a lot of people say, its quite tough to convert, so I have to start from rock bottom. So here will be a lot of experimenting tutorials for flash actionscript 3.0. In this Flash tutorial you will see how to load variables in to flash from a text file.
As you might know a variable is a container, we define a container to keep simple information, it can be text, numbers, true/false etc. In this case we just want to load in simple text variables from a text file we call content.txt (remember to keep the content file in the same directory as the flash file).
First we will look at how the text file is build, it really simple you write everything in one line, separating variables with a & and starting with the variable name then = to its value like this.
- var_1=first variable&var_2=second variable
Now for the flash file, here is first what we want to set up.
This small example will only contain two dynamic text fields, so go open a new flash document, and drag out two text objects, go to properties and change their state from static to dynamic and give the text boxes an instance name (I called mine content_1 and content_2) Look at the properties in the image below.
That was all we needed to do with the flash interface, of cause you can do a lot of visual stuff to make it look more interesting, but for this tutorial I will keep it simple and stick to the nerdy stuff.
As you know we are working with actionscript 3.0 so coding is done on the stage, so click somewhere on the stage, to deselect all, then go to the actionscript panel and type in the following code, lines with // are my comments on how the code works and what it does, you can delete them if you want.
- var loader:URLLoader = new URLLoader();
- //telling the loader that we are dealing with variables here.
- loader.dataFormat = URLLoaderDataFormat.VARIABLES;
- //This is an eventlistener, these are used all the time in AS3
- //learn to use them, this basically tells flash to listen to a specific event
- //and then call a specific function.
- //in Our case we listen for the even called COMPLETE which means it will active
- //a function called "loading" when our flash movie has completed
- loader.addEventListener(Event.COMPLETE, loading);
- //Here we tell our loading which file to extract from.
- loader.load(new URLRequest("content.txt"));
- //This is the function that will happen when the eventlistener activates.
- //basiclly it says that our text fields called content_1 and _2's text property
- //should be equal to loader.data.var_1 and var_2 (as you might remember from the explanation above).
- function loading (event:Event):void {
- content_1.text = loader.data.var_1
- content_2.text = loader.data.var_2
- }
sumber : http://blog.0tutor.com/post.aspx?id=110
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :