PDA

View Full Version : unable to access non-main classes in a package



Lazer57
November 8th, 2007, 09:00 PM
i am a newbie to AS3. i have some vid tutorials and a book. i am doing ok with AS3 on the timeline, but using classes is killing me. i have read through many other threads and have tried adapting the tips to my special circumstance but it isn't working. it has been over a week of now and again tweaking my approach and i can't get it to work. here is the setup.

files:
Geometry-RectangleArea.fla (in root)
Lesson.as (in root/lesson)
MoveMC.as (in root/lesson)(i just used this to try to duplicate a solution in another thread)

the document class for the .fla is lesson.Lesson

i put in a simple trace into the main class (Lesson.as) which does output. i am currently trying to move a MC object on frame 196, just so that i can know that non-main classes can work properly. here is the code:

on frame 196 of main timeline:
stop();
var mmc:MoveMC = new MoveMC(area4ftsq);

inside the Lesson.as file:


package lesson
{
import flash.net.*;
import flash.media.*;
import flash.display.MovieClip;
import flash.events.*;
import flash.display.SimpleButton;

public class Lesson extends MovieClip
{
public function Lesson():void
{
trace("hello dude");
}
}
}


inside MoveMC.as file:


package lesson
{
import flash.display.MovieClip;

internal class MoveMC extends MovieClip
{
public function MoveMC(area4ftsq:MovieClip)
{
area4ftsq.x -= 150;
}
}
}


the error i get:
1046: Type was not found or was not a compile-time constant: MoveMC.

would appreciate your help and patience.

Krilnon
November 8th, 2007, 09:20 PM
Your internal class, MoveMC, should be in the same AS file as the externally visible class, Lesson.

Omnimouse
November 9th, 2007, 12:02 AM
Alternatively, if you want classes to be visible outside their package, you can declare them as public rather than internal.

Lazer57
November 9th, 2007, 11:33 AM
I just tried copying and pasting the MoveMC internal class into the Lesson.as and i get the error:
1046: Type was not found or was not a compile-time constant: MoveMC.

Then I tried just changing internal to public, while leaving the MoveMC class seperately but still in the lesson package and it gave me the error:
ArgumentError: Error #1063: Argument count mismatch on lesson::MoveMC$iinit(). Expected 1, got 0.

I thank you for your help, but could you be more specific/exact because I really am a complete newbie and I am not sure if I did what you guys said to do.

Dazzer
November 9th, 2007, 11:56 AM
The last error is simple. Your constructor requires 1 parameter, but you did not supply any.

Don't be put off by error messages. Sometimes when you are fixing something you simply run into more errors, and you tackle them one at a time. Read the message, they are there for you to understand what is wrong.

Lazer57
November 9th, 2007, 01:13 PM
I thought I supplied one: area4ftsq:MovieClip

I am not familiar enough with the terminology or the errors to accurately target problems. Could someone make the alterations to the code I provided so that I can see how to fix it? I learn best that way.

morgate
November 9th, 2007, 02:29 PM
if you want to instantiate a custom class in another class, you have to import it

in your main document class just add:
import lesson.MoveMC;

and you should be good. now you're telling it to create a MoveMC type movie and not really telling flash where to go and look for it.

..and MoveMC does not have to be internal.. just set it to public if you want other classes to be able to access it.

Lazer57
November 9th, 2007, 04:04 PM
Thanks for the reply morgate. I am now at a new error. I really just need to get this working once and I can replicate it for the rest of my classes, so please continue to help guys.

When the movieclip that i want to eventually move first appears on the screen I get the following error:
ArgumentError: Error #1063: Argument count mismatch on lesson::MoveMC$iinit(). Expected 1, got 0.

Then when it gets to frame 196, which is where I want the movieclip to move I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at lesson::MoveMC$iinit()
at lesson::Lesson/lesson::frame196()

I have exported the movieclip for actionscript and I have set the class to lesson.MoveMC
I have set the MoveMC class to public and I imported lesson.MoveMC in the main class called Lesson. The document class is lesson.Lesson. I am not sure what is going on and the errors I am getting are unfortunately not helping because I don't know enough about AS3 to understand them. If you know what the problem is, please be very clear like morgate was. Thanks ahead of time.

Lazer57
November 10th, 2007, 07:49 PM
I solved the problem. All I had to do was change the baseclass of the movieclip to lesson.MoveMC

It was that simple, but I guess for a newbie most problems are simple issues. I am disappointed that it took me two weeks to figure that out. Unfortunately most of the materials I have for ActionScript 3.0 deal with it in general terms, typically in Flex Builder, which doesn't really explain how to tie it in with Flash CS3.