Still Some Problems with Classes!

Hi to all!!, I just got Macromedia Flash MX 2004 and started trying to make classes that build movies on my main screen (since this is the reason why I bouth it in the first place) … How ever I don know why it doesn’t want to create even a simple line!!!

I have attached the coding I have done so far, however below I placed the code of the function that is cousing the error:

[font=Courier New][color=slategray]/**[/color][/font]
[font=Courier New][color=slategray][/color][/font]
[font=Courier New][color=slategray]
/[/color][/font]
[font=Courier New][color=navy]public function[/color] LoadFrame(x:[color=navy]Number[/color], y:[color=navy]Number[/color], layer:[color=navy]Number[/color]){
[color=slategray]// Refreshing global variables.[/color]
frameXPos=x; [/font][font=Courier New][color=slategray]// Frame x co-ordinates.
[/color]frameYPos=y; [color=slategray]// Frame y co-ordinates.[/color]
frameLayerPos=layer; [color=slategray]// Frame layer position.[/color][/font]
[font=Courier New][color=slategray]// Creating the emoty movie clip that
// that will store the new frame objects.
[/color][color=navy]_parent[/color].[color=navy]createEmptyMovieClip[/color]([color=blue]“Frame”[/color], layer);

[color=navy]this[/color].Frame.[color=navy]createTextField[/color]([color=blue]“txtMessageArea”[/color], 1000, 20,20,100,20);
[color=navy]this[/color].Frame.txtMessageArea.[color=navy]text[/color]=[color=blue]“Hello”[/color];
[color=navy]this[/color].Frame.[color=navy]createEmptyMovieClip[/color]([color=blue]“container”[/color], 2);
[/font]
[font=Courier New][color=slategray]// Creating a simple line[/color]
[color=navy]with/color{
[color=navy]lineStyle[/color](0,0x000000, 100)
[color=navy]moveTo[/color](0, 0);
[color=navy]lineTo[/color](25, 0);
}[/font]
[font=Courier New][color=slategray]// Setting the frame settings.[/color]
[color=navy]this[/color].Frame.width = [color=navy]this[/color].frameWidth;
[color=navy]this[/color].Frame.height = [color=navy]this[/color].frameHeight;
[color=navy]this[/color].Frame._x = [color=navy]this[/color].frameXPos;
[color=navy]this[/color].Frame._y = [color=navy]this[/color].frameYPos;
[color=navy]trace/color;
}[/font]

The compiler tells me that the problem is with the [font=Courier New][color=navy]with[/color][/font] block (because can not find the [font=Courier New][color=navy]movieClip[/color][/font] container. However as you can see this movie clip is created exacttly before the [font=Courier New][color=navy]with[/color][/font] block. Also neither the text are created is being displayed.

I don’t know why there is the problem, all I know is that in the MX version it works :frowning:

I would be very greatfull to who ever know the answer for this problem. Thanks to all in advance!

actually, isnt Frame a keyword already used by Flash?

Usually Flash keywords are higlited in a dark Blue color, and Frame did not higlight for me!! I changed it to SFrame but it still gave the same problem … I dont think it’s the fault of the name!

I could be wrong. Just seems like one :crazy:

You could try tracing the movieclip (that you’re creating the things in) to make sure it exists before you try making things in it. If that does exist, then trace what you make in it to see if they exist. You might be able to find the trouble maker then

Are you exporting in Flash 7 or Flash 6? Also in Flash MX 2004 (exporting AS 2.0 and player 7) all variables must be declared before using them. It was not so in MX using AS 1.0. Have you done that? I hope that helps.

try changing this:

[AS]
_parent.createEmptyMovieClip(“Frame”, layer);
[/AS]

to this:

[AS]
this.createEmptyMovieClip(“Frame”, layer);
[/AS]

you should not be using _parent and this. ask yourself what these refer to.

First of all Thanks and sorry for not replying immediatlly, but I was at my aunties house and there aren’t any computers there :frowning:

I tried not to use the _parent and this, but when I did that it gave me the following error: No function with name createEmptyMovieClip found!!

I don’t think the class is creating anything coz neither the first movie were I am placing the TextBox is being dispalyed in the movie.

I feel as if i need a cry :’(

Thanks to all again :slight_smile:

ok, ok. let me take a closer look.

So… this is in a class I take it? What is the class called? Is it correctly extending MovieClip? Do you have a MovieClip associated with this class in the library and are you correctly attaching it in the timeline? Have you traced the instances of the clips you are trying to create to make sure they exist first? Making sure no conflicting depths?

Hi This explnation should be correct: I want to create classes that when used will create objects on the different frame. I want that with my classes I can do the following coding in my .fla files to create new items:

[font=Courier New]var M:MessageBox = new MessageBox(“Say Hello”);[/font]
[font=Courier New]M.show();[/font]

Which in the above code the first I would be creating a new instance of type [font=Courier New]MessageBox[/font] and then I by calling the method show() I would be painting the [font=Courier New]MessageBox[/font] on the current Frame of the movie were the instance is being created. Now I tried this in Flash MX with just creating a text box and a line (With a big thanks to Voetsjoeba for his help), however when i tired the same code (with only some modifications to be like Flash MX 2004 style) the code did not work!, example if i don’t use[font=Courier New] _parent[/font] the flash compiler will not want to read the class file!!

Naturally the advantage of such code is reusibility, and since I liked Java and C alot I would really like to impliment this in Flash.

btw - Thanks for the interest, I really apreciate it by you guys :slight_smile:

well, like that, you shouldnt be able to use _parent at all. Class objects have no _parent. Only movieclips do (unless you explicitly give your objects a _parent property which I dont think you did).

If you’re not associating your class with a movieclip and creating an instance of that class by attaching the associated movieclip to some timeline, then you can forget about using _parent. What you might consider instead is to pass in the timeline of choice as an argument and use your class to attach instances to that object (saved in your class as a property).

[font=Courier New]var M:MessageBox = new MessageBox(_root, “Say Hello”);
M.show(); // creates textfield in _root to show “Say Hello”[/font]

ok, i know i shouldn’t hijack this thread, but…
what is this public function stuff all about? and the x:Number? I have never saw that before.

Thats from ActionScript 2.0.

the public keyword is used in class definitions and defines a method as being “public” or accessible for use directly off the instance object. Those which are not public are private. Private methods cannot be used from the instance. Instead, they are for use only from within the class itself.

x:Number is a way of specifying variable type. Using a colon (:slight_smile: and an Object type following a variable name when its declared or initially defined, you can dictate its type. This helps you prevent yourself from trying to assing a number to variable which should be a string. It isnt required, but its good to do.

go to this website and download the classes under chapter 5. oh, buy this book too.

http://moock.org/eas2/examples/

first of all thanks Rosrag for the link … abouth the Parent thing: from how I could understand it [font=Courier New]_parent[/font] would only means that it will create the new movie in the parent of the the movie being created!!

If I send the _root it would always load the movie clip in the root movie and could create, problems when haveing different swf files loaded in each other.

Can I send instead in which movie clip to load it? example:

[font=Courier New]var M:MessageBox = new MessageBox(this, “SayHello”);[/font]
[font=Courier New]M.show();[/font]

and in this cas how should in the constraucter the coding shoudl be something like this? :

[font=Courier New]public function MessageBox(parent:MovieClip, title:String){ [/font]

[font=Courier New]…[/font]

[font=Courier New]}[/font]

??

yes, that is what I meant, _root was just an example - though, as a parameter of the constructor it is its purpose to allow any other argument to be passed, beit _root or this.

Yes that would be great, coz it’s the same thing I used in Java! … but what should be the instance of that variable, MovieClip???

I am refering to the parameters, they should be like this:

[left][font=Courier New]public MessageBox(parent:MovieClip, text:String){[/font][/left]
[left][font=Courier New]…[/font][/left]
[left][font=Courier New]}[/font][/left]

and then can I do this:

[font=Courier New]parent.createEmptyMovieClip(…);[/font]
Thanks Man!! :slight_smile:

yup

Ok … I’ll work on it tomorow and then tell you if it works! :slight_smile:

Thanks for all the help!! … i was going to fire my head!!

Thanks again :slight_smile: