PDA

View Full Version : Drawing in Class definition



playing_life
August 25th, 2008, 03:53 AM
Hi everybody,
I am sorry if this is a stupid question but I have searched for the last 3 days and I did not find an answer to this.

I want to create a class which extends a MovieClip class and I am trying to have in te constructor of the class to draw some graphic. Is this even possible of is there something I do wrong? I get no error but I can't see anything on the screen.

Code in Flash:
-------------
var tabel = new data_matrix();
-----------------------------

Code in text editor - where I buid the class:
------------------------------------------
class data_matrix extends MovieClip{

public var dshape:MovieClip;

function data_matrix(){
dshape=this.createEmptyMovieClip("dshape1",100);
dshape.lineStyle(0, 0xFF0000, 100);
dshape.lineTo(100, 0);
dshape.lineStyle(0, 0x00FF00, 100);
dshape.lineTo(100, 100);
trace(this._name);
}
-------------------------------------------

Also the trace command above displays UNDEFINED like the object is not even defined.

I thank you very much in advance.

wvxvw
August 25th, 2008, 04:09 AM
You probably posted in the wrong forum. Your code is AS2, not AS3... Also the trace output will depend on what were you doing to your class before, however the data_matrix function itself is OK except for the missing namespace and typing.

playing_life
August 25th, 2008, 04:16 AM
I am sorry for the missplace of the thread.
I was trying to display the name of the object I have just created, "table".
What I want is that when I create a new object based on the class that I have defined, data_matrix, to create some graphic in the constructor.
And please what do you mean by missing namespace and typing.
Thank you

TheCanadian
August 25th, 2008, 04:16 AM
In AS2 you can't instantiate MovieClip's (or a sub-class) for display on the stage using the new operator. You must create association with a movie clip in the library and use attachMovie or drag an instance to the stage to create the instance.

playing_life
August 25th, 2008, 04:25 AM
Thank you very much... I will read about AS3 now to see the differences.

TheCanadian
August 25th, 2008, 04:32 AM
Are you using AS3 or AS2? Cause right now you're trying to do both and it's obviously not going well :P

wvxvw
August 25th, 2008, 07:41 AM
I am sorry for the missplace of the thread.
I was trying to display the name of the object I have just created, "table".
What I want is that when I create a new object based on the class that I have defined, data_matrix, to create some graphic in the constructor.
And please what do you mean by missing namespace and typing.
Thank you

Hm... you either haven't written the constructor function or haven't posted it... But if you have one and call data_matrix() from it than it should trace something like [object Object], if it's AS2.
Namespace, speaking of AS may be either private or public, in AS3 there're much more + you can create custom namespaces. By typing I meant defining the return type of the function like this:

private function someFunction():SomeType {};
And, yes, you have to decide which version of AS you want to use, you cannot use them both together =)

playing_life
September 8th, 2008, 02:38 AM
Thank you very much guys