Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

How to call another class from the Document Class with Flash CS3

This is a discussion on How to call another class from the Document Class with Flash CS3 within the Tutorials forums, part of the Flash English category; Hello people, In my opinion we have 2 valid and concrete ways to initiate another class from the Document Class (...


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
  #1 (permalink)  
Old 09-10-07, 19:50
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
How to call another class from the Document Class with Flash CS3

Hello people,
In my opinion we have 2 valid and concrete ways to initiate another class from the Document Class (Main Class).
1: We write the Class to initiate exactly like the Document Class.
2: We write a Class in the same AS file of the Document Class, but outside the package.

There would be other ways, like for example taking advantage or the inheritance of the Document Class, but I?d enter a subject that I don?t want to cite in this article, so I?ll postpone it to future articles.
A concrete example ( so that nobody thinks we only talk here ), I create an FLA?


and I save it as ?chiamate.fla?. I create an AS file and save it as ?Prima.as?. I define the Prima class:
Code:
package
{
	import flash.display.MovieClip;
	public class Prima extends MovieClip
	{
		private var la_seconda:Seconda;
		
		public function Prima()
		{
			la_seconda=new Seconda();
			var la_terza:Terza=new Terza();
		}
	}
}
import flash.display.MovieClip;
class Terza extends MovieClip
{
	public function Terza()
	{
		trace('La classe Terza è stata istanziata');
	}
}
where you can see I?ve also defined another class called Terza, still in the same file, but outside the package.
Now I create another AS file, I save it as ?Seconda.as? in the same folder where both the FLA and Prima.as and I define the Seconda class this way (exactly like Prima-as):
Code:
package
{
	import flash.display.MovieClip;
	public class Seconda extends MovieClip
	{
		public function Seconda()
		{
			trace('La classe seconda è stata istanziata');
		}
	}
}
These are 2 ways to initiate other classes from the Main Class, exactly like a pure OOP application.
It?s the best way to start our Flash application.
I?d like to give you a citation by Colin Moock ( Actionscript architect ) who I?ve always appreciated and whose advice I follow:
?In a pure Object Oriented Flash application, a FLA file might contain only a single frame, which simply loads the application's main class and starts the application by invoking a method on that Main Class.?
This way we?ll have total control of our classes and their methods and properties, but more than anything we?ll have an application with only one frame and completely modular.
Analyzing the 2 classes I?ve written, you can notice that the Seconda class is initialized as a property of the Main Class, while the Terza class is instantiated with a local variable inside of the constructor ( see the article ?How to create a class in Actionscript 3.0? to know more about the constructor ) of the Main Class, so being a local variable, as it?s born it dies and can?t be recalled ( in this case only within the execution of the constructor code).

Have fun !
__________________

 


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
Call from the timeline to the Document Class and vice versa with Flash CS3 Flep Tutorials 6 11-12-08 14:15
chiamate dalla timeline verso la Document Class e viceversa con Flash CS3 Flep Articoli e tutorials 13 01-12-08 06:03
La Document Class di Flash CS3 Flep Articoli e tutorials 1 23-04-08 11:21
document class marco792005 Actionscript 3.0 base 3 13-01-08 09:16
The Document Class of Flash CS3 Flep Tutorials 0 23-09-07 17:58


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

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