Sunday, August 9, 2009

Motion Guide Tutorial

Motion Guide is a line which is the path along which you want an object to move
I'll be using Adobe Flash CS4 from now on and start with AS3 tutorials after i learn it. If you're using an older version of Flash you can follow the tutorials just as well.

1. Create two layers and name the top one Guide and the one below it Obj. You can name them anything you want but
you should name your layers according to what they contain. Here the Guide layer will contain the Motion Guide and the
Obj layer will contain the object to be guided

2. Select the first frame of the Guide layer. Select the Pencil Tool
and draw the path you want the object to move on.This line will be your Motion Guide.
3. Now draw your object. To do that hit Ctrl+F8 to bring up the Create New Symbol Box. Name it as obj_mc
I'll draw a simple circle with the Oval Tool.You can make the object to look like whatever you want.
4. Right click on the Guide Layer name and select Guide. This will make the line on that layer a Motion Guide.



If You do it correctly the layers will look like this. Now pay attention. Click on the Obj Layer name
and while pressing the mouse button make an upward motion with the mouse. When you Release it your layers should look likeYou have assigned the Guide layer as the motion guide of the Obj Layer.
5. In the Library window you will see your obj_mc object. If you cannot find your Library window go to Window->Library or hit Ctrl+L. Now Select the fisrt frame of the Obj Layer and drag the object from the library to the top end of the
guide line.
Now go to the timline and on each layer Right Click on the 30th frame and select "Insert KeyFrame". your timeline should look like this
Now select the last frame of the Obj Layer and Drag your object to the end of Motion Guide. The little circle in the centre should snap on to the line. Now select any frame of the Obj Layer and Select "Create Classic Tween".
You're done.
Hit Ctrl+Enter to test the movie.
6. If the Movie is very fast you can do two things. Firstly increase the number of frames. Here we are using 30 or you can hit Ctrl+J and in the window that pops up reduce the Frames per Second(fps) to a lower value. Default fps in CS4 if 24.

Sunday, July 26, 2009

Load Text From an External Text File using Action Script

There are two ways you can load data from an external text file:
1. You can load the whole text present in the file
2. Or you can format the text so that you can load in parts if you want to.

To Begin create a text file myText.txt or whatever you like and copy and paste the following text in it

&monthNames=January,February,March,April,May,June,July,August,September,October,November,December &dayNames=Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

"&monthNames" and "&dayNames" are the labels which will help us to acess a part of the data. You can name
them in any way you like such as "&part", "&xxx" or "&whatEverILike". All the parts you would like to access
should have a different label.

Now create a file loadText.fla and save it in the SAME FOLDER as the text file.Create a second layer and name
it "Action". Select the first layer and click on the Text Tool and go to properties panel and set the Text Type
as Dynamic Text and select the Line Type as Multiline then create three text fields.








Select each one at a time and give their instance name in the
Properties Panel as monthnames_txt, daynames_txt and alltext_txt respectively. Create small Satitc Text boxes on top
of each previous text boxes and create labels. At the end of these steps your stage should look somewhat like this.


That done right click on the first frame of the Action layer and select Actions
In the window that opens copy and paste the following script. I think it's sufficiently documented.


//declare two objects of the LoadVars class to load the text file
var text_lv:LoadVars = new LoadVars();
var text1_lv:LoadVars = new LoadVars();

text_lv.load("myText.txt");//load file to display in parts
text1_lv.load("myText.txt");//load file to display the whole text

//display the text in parts
text_lv.onLoad = function (success:Boolean)
{
if (success)
{
monthnames_txt.text =text_lv.monthNames;//show text labelled as "&monthnames"
daynames_txt.text =text_lv.dayNames;//show text labelled as "&daynames"
}
else
{
monthnames_txt.text = " Cannot Open File ";//error message
}
}

//display the whole text
text1_lv.onData = function (myText:String)
{
alltext_txt.text = myText;
}



That's it! Hit Ctrl+Enter to test. If the text is not visible make sure the color of the text fields is not the
same as the background color, also check that you have saved the flash file and the text file in the same folder.