To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > General Help > Games

Reply
 
Thread Tools Search this Thread Display Modes
Old 07-02-2007, 01:29 PM   #1
Cortana
Developer
 
Join Date: Apr 2007
Location: UK
Posts: 324
[AS3] Class Access Problem

I'm very sorry for double posting this but as this problem is with a game I'm making and a LOT more people frequent here than the AS3 forum I suppose it isn't too bad if I post here. Anyways here goes..

I have a Main class in the fla's directory

I have a Waters folder which contains WaterHandler and Water1

The Main class imports Waters.WaterHandler

WaterHandler when asked, needs to make a new Water1.

This is where it messes up. For some reason WaterHandler doesn't create the Water1 that is in the Waters directory - it creates a fake one which means when I try and access Water1's methods it says they arent there.

Weirdly enough, if I put WaterHandler and Water1 in the fla's directory everything works fine. But I want all of my files to be nicely organized.

Also, if I use:

var test = new Waters.Water1();

from WaterHandler it creates the proper Water1. But why should I have to do that if its already in the same package?

What am I doing wrong? Why cant I simply use 'new Water1()' from WaterHandler successfully seeming as they are in the same directory?

And yes I've declared both Water1 and WaterHandler as part of the Waters package. And I've also tried importing Waters/Water1/Waters.Water1 to no avail.

Thnx in advance!

Last edited by Cortana; 07-02-2007 at 01:32 PM.
Cortana is offline   Reply With Quote
Old 07-02-2007, 01:55 PM   #2
AfternoonDelite
Senior Member
 
Join Date: Jan 2006
Location: USA
Posts: 383
The only thing I can think of is that there may be something wrong with the way you're declaring the packages.

So.. how are you declaring the packages?

Your main class could just have the default package.

PHP Code:
package {
    
import Waters.WaterHandler;
    public class
Main {
        private var
waterHandler:WaterHandler;
        public function
Main() {
            
waterHandler = new WaterHandler();
            
trace(waterHandler.getWaterPressure());
        }
    }
}
and then the two classes inside your Waters folder:

PHP Code:
package Waters {
    public class
WaterHandler {
        private var
water1:Water1;
        public function
WaterHandler() {
            
water1 = new Water1(2);
        }
        public function
getWaterPressure():Number {
            return
water1.getPressure();
        }
    }
}
PHP Code:
package Waters {
    public class
Water1 {
        private var
pressure:Number;
        public function
Water1(_pressure:Number) {
            
pressure = _pressure;
        }

        public function
getPressure():Number {
            return
pressure;
        }
    }
}
AfternoonDelite is offline   Reply With Quote
Old 07-04-2007, 11:11 AM   #3
Cortana
Developer
 
Join Date: Apr 2007
Location: UK
Posts: 324
I found out what my problem was!

My code was completely correct (just like your AfternoonDelite). What was wrong was that I had a Water1 MovieClip in my Library and its class was defined as Water1 instead of Waters.Water1 which was why it wasn't working. Now I've renamed it everything works perfectly!

Im so glad I found the error
Cortana is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > General Help > Games

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off

Forum Jump


All times are GMT -4. The time now is 02:30 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.