Actionscript & Shared functioins

I am working with some AS classes trying to become more OOP in nature, and so I am testing keeping everything organized in separate folders according to tasks. You know the drill I like to keep the AS classes in my com folder and inside their separate different classes by what they might do. Shapes in one folders, text in another and so on.

I have been trying this shapes example I came up with with calls another AS class. This works fine when they are both in com, but when they are bother in their own separate folder I get an error.

This is the example when everything is in the same folder

package {

	import flash.display.Sprite;

	import flash.filters.GlowFilter;

	import flash.filters.DropShadowFilter;

	import flash.filters.BlurFilter;

	import Triangles;

	public class InheritingClasses extends Triangles {

		public function InheritingClasses() {

			triangle1.filters = [new GlowFilter(0xFF6699, .75, 25, 25, 2, 2, false, false)];

			triangle2.filters = [new DropShadowFilter(5, 45, 0x666666, 1, 5, 5, 1, 1, false, false, false)];

			triangle3.filters = [new BlurFilter(5, 5, 2)];




package {

	import flash.display.Sprite;

	import flash.display.Shape;

	public class Triangles extends Sprite{

		internal var triangle1:Shape = new Shape();

		internal var triangle2:Shape = new Shape();

		internal var triangle3:Shape = new Shape();

		public function Triangles(){, 0x000000);, 1);, 100);, 100);, 225);, 225);;

			addChild(triangle1);, 0x000000);, 1);, 50);, 50);, 50);, 175);;

			addChild(triangle2);, 0x000000);, 1);, 375);, 375);, 250);, 350);;





of course I set the doc class to “InheritingClasses”

Now when I create the com folder, and put the in “classes and in “Shapes” I got a weird error.

Attempted access of inaccessible property triangle1 through a reference with static type com.classes:InheritingClasses.

Attempted access of inaccessible property triangle2 through a reference with static type com.classes:InheritingClasses.

Attempted access of inaccessible property triangle3 through a reference with static type com.classes:InheritingClasses.

Now why would this fail when I separate the as files into com/shapes for and com/classes for the main class? Of course I updated everything to reflect this change.

I asked this question on Linkedin and Jeff Fall tells me to use public static in the function,and I will try this tonight.

4 thoughts on “Actionscript & Shared functioins”

  1. Johnny,

    Assuming this change is complete and correct: “of course I updated everything to reflect this change,” the reason this is happening is because of namespaces. In the code you cited above, you’re using internal for your instance properties. That namespace gives access to your properties to all classes in the same package. Therefore, while all your classes are in com, or hfug, or any other package directory, the InheritedClasses class will recognize the instance names triangle1, triangle2, etc.

    However, when you move the classes to separate packages, no matter what they may be, InheritedClasses doesn’t recognize those instances. If you then changed “internal” to “protected”, which grants access to the class and subclass, the fact that InheritedClasses extends Triangles means the former will know about the instances.

    It will be a great exercise to change the name spaces among public, private, protected, and internal and see what changes you have to make to the classes to get the example to work. Then you might consider changing the structure around a bit. It seems a little like putting the cart before the horse. If you decide to reorganize, however, do it last. You’ve fallen into a great test case to learn about the four namespaces.

  2. Hi Rich,

    Thanks so much for your comment!

    Yep, when I used “protected” or “public” it worked fine. As for the “private”,”internal” name spaces did not. I am very interested in seeing what I have to do to get them to working in the same way.

    This is interesting as doing this example will teach me about name spaces in AS 3!

    When I figure this out, I think that it will make a very interesting blog post`-`

  3. howdy fabulous little blog you have there πŸ˜‰ I work with the same exact theme on mine but for whichever cause it looks to load speedier on this web site despite the fact that this site is carrying a whole lot more material. Are you using any sort of plugins or widgets that quicken it up? Do you think you could show the titles so maybe I would be able to use these on my own site so twilight new moon followers could watch twilight new moon online trailers and clips a lot quicker I’d personally always be grateful – thanks ahead of time πŸ™‚

Leave a Reply