View Full Version : Use of packages
jsimpson
May 8th, 2007, 12:59 AM
I'm slowly making the move to AS3 and am having a few difficulties along the way. One is packages, specifically the scope ans use of them.
Does the package name have to reflect the directory structure. Can I have something like this:
package com.media.news{
Without that being the current directory structure? Or must the directories reflect the naming convention? Also what is the scope of calling import on a package?
Say the full path is flash/actionscript/com/media/news... can I import that package from flash/testing/curProject?
Also one last question. If I wanted to build a package that was a library of functions, could I do this?
package utils{
public function f1(){}
public function f2(){}
}
Thanks for any help.
Dazzer
May 8th, 2007, 02:13 AM
1) as of CS3, yes the package identifier needs to reflect the directory structure (at least that was what it told me when I tried to compile my public ALPHAprojects)
2) I don't get your 2nd question
3) no. Packages needs to contain a class. However, you could create a class with static functions
package my.components.in.directory
{
public class myStaticFunctions
{
public static SayHello():void
{
trace("HELLO!!!!!!!!");
}
}
}
import my.components.in.directory.myStaticFunctions;
public class documentClass extends MovieClip
{
public documentClass():void
{
myStaticFunctions.sayHello(); //Traces HELLLO!!!!!
}
}
TheCanadian
May 8th, 2007, 02:15 AM
Does the package name have to reflect the directory structure.Can I have something like this:
package com.media.news{
Without that being the current directory structure? Or must the directories reflect the naming convention?
Package names do reflect directory structure, so the package com.media.news would have to been in the directory com/media/news relative to the loaction of your FLA or a global class path.
Also what is the scope of calling import on a package?
Say the full path is flash/actionscript/com/media/news... can I import that package from flash/testing/curProject?You would need to create a global class path for the flash folder. I'm not to sure how this is done in CS3.
Also one last question. If I wanted to build a package that was a library of functions, could I do this?
package utils{
public function f1(){}
public function f2(){}
}
You can do that, but each function must be in its own AS file.
Rezmason
May 8th, 2007, 03:00 AM
If I wanted to build a package that was a library of functions, could I do this?
package utils{
public function f1(){}
public function f2(){}
}
You can do that, but each function must be in its own AS file.
For this reason (having to deal with multiple files) and others, it's a better idea to use a static class rather than a package to store functions in this way.
eudora
May 8th, 2007, 03:02 AM
If you just want functions.. use "include"
So in my functions.as, i would have
function a():return{
}
function b():return{
}
Then in the classes which need these function, add the
"include functions.as" within the class alongside its variables.
Aquilonian
May 8th, 2007, 05:43 AM
wrong post,ignore it
jsimpson
May 8th, 2007, 09:06 AM
Thanks everyone, you've answered all of my questions! Have a great week!
dthought
May 8th, 2007, 08:21 PM
Of interest, the com part is actually to do with the URL of the company. For example, com.macromedia means it came from macromedia.com. It doesn't stand for anything, so you are not obliged to use com as a naming convention.
The package names are merely to ensure uniqueness, and a good way of doing that is by using your website's URL in reverse order and sans anything such as www.
For example, in my case I may choose to make my custom packages under net.dthought, because that's my site URL in reverse.
Rezmason
May 8th, 2007, 08:29 PM
Has anyone here got a favorite subdomain? net, com, org? :) I prefer net, it has a bit more of a grassroots feel than the others.
Dazzer
May 8th, 2007, 10:10 PM
From a business perspective, .com is always better. But .net is gaining the "Household name" status rapidly so its okay too.
TheCanadian
May 9th, 2007, 02:06 AM
Of interest, the com part is actually to do with the URL of the company. For example, com.macromedia means it came from macromedia.com. It doesn't stand for anything, so you are not obliged to use com as a naming convention.
The package names are merely to ensure uniqueness, and a good way of doing that is by using your website's URL in reverse order and sans anything such as www.
For example, in my case I may choose to make my custom packages under net.dthought, because that's my site URL in reverse.
That really annoys me when people use com in their package names arbitrarily. Haha I don't know, I'm an idiot like that sometimes :P
Dazzer
May 9th, 2007, 04:58 AM
i just call my packages darylteo
eg: darylteo.display.CustomButton
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.