ActionScript Tutorials and Code


Interfacing Flash with external data sources



Macromedia Flash is a very robust tool for creating multimedia applications for both the internet and other applications It’s use has been documented as widespread as the PlayStation 2™ Incarnation of the game ridge racer. The key to this use of flash is being able to use flash with external data sources such as XML and text documents.

In this tutorial we will investigate how to create a text reading application for use as a guestbook this way you could create the application and instead of opening up flash you would be able to change the contents of the text file and have the page updated on the fly.

Before starting this tutorial you must ensure that you have at east Macromedia Flash MX these tutorials may work elsewhere but I can only guarantee their success within Flash MX and upwards.

Step1:
Create a New flash Document in the standard document dimensions 550px width and 400px height.

Step2:
Use the Text Tool to create a Dynamic Text Box with a variable name of text and the value Single Line change to Multiline.

Step3:
Right Click the first Frame and select Actions from the context menu.

Step4:
Use LoadVariable(“./data/textfile.txt”, _root); and then stop(); in the ActionScript window then click the arrow to make the Actions screen disappear.

Step5:
Now You can save the Flash source file and Export to an SWF file the flash part of this exercise is finished.

Step6:
Now you need to go into windows explorer and create a folder with the name data in the directory that you saved your flash file to.

Step7:
Inside this data directory create a file entitled textfile.txt with contents reading &text=hello this is my file

Step8:
Run your flash file and The text “hello this is my file” appears in the window.

Step9:
Now you have an application that works you can change the font in the flash application or pretty much anything you desire. I hope this helps you to create future flash masterpieces.



Rotation in Flash


Rotation



This tutorial is the underpinning of many websites and can help you in game design and also many websites use rotation alongside zooming effects. The bottom line is that even though this is simple enough to do it is still very important

Step1:
Create a New flash Document in the standard document dimensions 550px width and 400px height.

Step2:
Use the Text Tool to create a Static Text Box with the text saying something like “Rotation” or “Im Spinnin”.

Step3:
Right Click the text box and select convert to symbol from the context menu.

Step4:
Click on frame 35 and press the F6 key which is used to create a new keyframe.

Step5:
Now click on the Align & Info & Transform panel and select the rotation box which should read 0˚ and change it to read 350˚.

Step6:
Click on frame 1 and select Insert->Create Motion Tween

Step7:
Now click on frame 18 and press F6 once again so as to create a new keyframe.

Step8:
Now once again click the Align & Info & Transform panel and click on the field entitled rotation and change it’s value to 180˚.

Step9:
Now you have an application that works you can press the Enter key to view the movie this is the end of the rotation tutorial and you can play around applying your newly learned rotation techniques to shapes, bitmaps and movie clips for some really interesting effects.

Alternative Step1:
Create a New flash Document in the standard document dimensions 550px width and 400px height.

Alternative Step2:
Use the Text Tool to create a Static Text Box with the text saying something like “Rotation” or “Im Spinnin”.

Alternative Step3:
Right Click the text box and select convert to symbol from the context menu and choose MovieClip.

Alternative Step4:
In the properties panel assign the MovieClip the name "spin".

Alternative Step5:
Activate the actions panel (F9).

Alternative Step6:
paste in the below code


onClipEvent(enterFrame){
    this._rotation += 10;
}


Alternative Step7:
Now you have an application that works you can press the Enter key to view the movie this is the end of the rotation tutorial and you can play around applying your newly learned rotation techniques to shapes, bitmaps and movie clips for some really interesting effects. Oh yes and if you want it to rotate like it did in the original motion tween try editing the movieclip so that the text is aligned to the horizontal and vertical center whilst being snapped to the stage.

Reference: http://www.geekpedia.com/language22_ActionScript.html


Written by