Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-20-2007, 09:23 PM   #1
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,991
Send a message via Skype™ to panel
Question Linkage MC to Class in package?

Hi

I am creating package in File Test.as
Code:
package
{
	import flash.display.*;
	import flash.text.TextField;
	
	public class Test extends Sprite
	{
		public function Test()
		{
		}
	}
	
	public class Test2 extends Sprite
	{
		public function Test2()
		{
		}
	}
}
I am importing this package
Code:
import Test;
I can create Test Object and Test2 Object
Code:
t = new Test();
t2 = new Test2();
My point is that flash 'see' booth classes here, but when I try to linkage mc in Library with class flash 'see' only Test Class.
When I try linkage to Test2 I am reciving error

A definition for this class not to be found on disk, so one will be automatically generated upon export.

Why Flash don't 'see' Test2 class and how to deal with it?

Last edited by panel; 03-20-2007 at 09:26 PM.
panel is offline   Reply With Quote
Old 03-20-2007, 09:46 PM   #2
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

Technically, Flash shouldn't even "see" Test2. Each class should have its own .as file as that file itself partly defines the class it contains. If you want to use Test2, you should put it in its own file. In fact its good practice to do that anyway.

(also you dont need to import your class unless its in a named package)
__________________
(6)

Last edited by senocular; 03-20-2007 at 09:51 PM.
senocular is offline   Reply With Quote
Old 03-20-2007, 10:19 PM   #3
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,991
Send a message via Skype™ to panel
Default

I understand but it seems iracional for me in this case

Packages should be used to group classes. Yes?
I would be nice to have one main class and few 'decorator' clases in one file?


But more confusing for me is fact that
Quote:
Originally Posted by senocular View Post
Technically, Flash shouldn't even "see" Test2.
It looks like Bug to me....becouse completly I don't see pioint here...those 'differences' are confusing

Quote:
Originally Posted by senocular View Post
Each class should have its own .as file as that file itself partly defines the class it contains.
In this case do we need packages at all?

Last edited by panel; 03-20-2007 at 10:26 PM.
panel is offline   Reply With Quote
Old 03-20-2007, 11:09 PM   #4
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

Packages are for organization. They give you a location to store ActionScript files not only on your file system but also in code. You use packages to group like classes and to prevent naming conflicts with other classes. They are not required but are often very helpful, especially in larger projects and when reusing or distributing code.

The fact that Flash 9 Alpha can recognize more than one class in a single package block in a single file is just a "feature" of that app's compiler. Flex 2, however, will not recognize those classes, and since Flex 2 is a production-quality application (and not an alpha) you should be using it as a model for class definitions. There is no assurance that the next release of Flash will support multiple classes in one class block in one class file.

For more information, see a previous discussion of the package block here:
http://www.actionscript.org/forums/s....php3?t=128936
__________________
(6)
senocular is offline   Reply With Quote
Old 03-21-2007, 10:40 AM   #5
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,991
Send a message via Skype™ to panel
Question

Thanks senocular you were very helpfull.

As you said I have split classes into separate files (ClassName.as) and created package in each file.
When package dosen't have name everything is ok
Code:
package
{
	import flash.display.*;
	
	public class test extends MovieClip
	{
		public function test()
		{
			trace("created");
		}
	}
}
Code:
t1 = new test()
this.addChild(t1)
Now when I am trying to add package name

Code:
package myPackage
{
	import flash.display.*;
	
	public class test extends MovieClip
	{
		public function test()
		{
			trace("created");
		}
	}
}
Code:
import myPackage.*;

t1 = new test()
this.addChild(t1)
Flash 'see' test class, becouse constructor is called, but also throws error:
ReferenceError: Error #1065: Variable test is not defined.
I can still linkage my 'library MC', but becouse of this error mc dosen't apear on stage

Last edited by panel; 03-21-2007 at 10:47 AM.
panel is offline   Reply With Quote
Old 03-21-2007, 02:42 PM   #6
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

is the class saved in the folder myPackage?
__________________
(6)
senocular is offline   Reply With Quote
Old 03-21-2007, 03:10 PM   #7
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,991
Send a message via Skype™ to panel
Thumbs up

Quote:
Originally Posted by senocular View Post
is the class saved in the folder myPackage?
Thanks again
panel is offline   Reply With Quote
Old 03-21-2007, 05:24 PM   #8
dr_zeus
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

If your class Test2 is a helper class that should only be used by Test1, you can do something like this:

Code:
package
{
	import flash.display.*;
	import flash.text.TextField;
	
	public class Test extends Sprite
	{
		public function Test()
		{
		}
	}
}
	
class Test2 extends Sprite
{
	public function Test2()
	{
	}
}
Notice that Test2 is outside the package block and it doesn't have an access keyword like public. This class is now only accessible by Test1, and no other class can use it.
__________________
Josh Tynjala | Feathers
dr_zeus is offline   Reply With Quote
Old 03-21-2007, 05:56 PM   #9
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,991
Send a message via Skype™ to panel
Default

I have another problem - 2 simple classes:

Code:
package myPackage
{
	import flash.display.*;
	
	public class Fruit extends MovieClip
	{		
		public var _weight:Number;
		
		public function Fruit()
		{
		}
		
		public function getWeight():Number
		{
			return _weight;
		}
	}
}
Code:
package myPackage
{
	import flash.display.*;
	
	public class Banana extends Fruit
	{
		public function Banana(weight:Number)
		{
			_weight = weight;
		}
	}
}
Everything works fine until I linkage 'Library MC' to Fruit Class. Then all properties/methods in Fruit class act like private
Is there any way to solve this problem and get access to Fruit methods?
panel is offline   Reply With Quote
Old 03-21-2007, 06:23 PM   #10
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

I dont see anything wrong with that. What error are you getting?
__________________
(6)
senocular is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the mx.util.Delegate class within your classes! madgett ActionScript 2.0 3 09-02-2007 11:11 PM
Flash Remoting with Perl dopefries Flash Remoting 3 02-17-2007 01:42 PM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM
card game: designing Deck class and good OOP? pigpen Gaming and Game Development 1 11-26-2002 11:41 AM


All times are GMT. The time now is 11:41 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.