PDA

View Full Version : class friends


amansoori
02-09-2006, 08:26 PM
I need to make one of my classes called Point_obj a friend of my other class called Line_obj.
then I need to define a variable called myPos of type Point_obj.
Point_obj will contain some functions like get_fake_pos() or get_real_pos.

I'm fairly new to classes in AS 2. So i appologize if my question is stupid. but i still would like some help.
Thank you very much
this is what I have as an example just to make the conncetion work. but it doesnt.
-----------------------------------

this is my Point_obj

class Point_obj extends MovieClip
{
var myX;
var myY;
public function get_color_fcn():Void
{
trace("get_color_fcn");

}
public function get_transparency_fcn():Void
{
trace("hi");
}

}
--------------------------------------

this is my Lines_obj

class Lines_obj extends Point_obj implements Shapes_obj
{

var myPos:Point_obj;

public function setColor():Void{
trace("in setColor");
}
public function display():Void{
trace("in display");
}

}
-----------------------------
This is done on the main frame of my flash page.

_root.createEmptyMovieClip("myTestMovie",544);
mytest = new Lines_obj("myTestMovie");
mytest.myPos.get_color_fcn; //this doesnt work????
mytest.display(); //this works...

deadbeat
02-09-2006, 08:31 PM
Your Lines_obj class is neither creating, nor recieving a reference to,a Point_obj instance anywhere - so there is no object to call the get_color_fcn fucntion on...

Also, this line:
mytest.myPos.get_color_fcn;

Should be: mytest.myPos.get_color_fcn(); - you need the parentheses to make it a function call...

K.

devilmaycry
02-09-2006, 08:35 PM
in the class Lines_obj
this var myPos:Point_obj;
is undefined make a custructor

class Lines_obj extends Point_obj implements Shapes_obj
{

var myPos:Point_obj;
public function Lines_obj(){
Point_obj=new Point_obj();
}
public function setColor():Void{
trace("in setColor");
}
public function display():Void{
trace("in display");
}

}

senocular
02-09-2006, 08:38 PM
First, ActionScript doesn't support friends. You will have to make your methods/properties public in order to be accessible from other classes. However, private properties are also more protected than private... so subclasses do, in fact, have access to all of their superclass's members, private or otherwise.

Secondly, you aren't instantiating your movie clips properly. When you have classes that inherit from MovieClip, they are instantiated by the creation of the movie clip, not from the new keyword. For more information, see:
http://www.senocular.com/flash/tutorials/faq/#newmovieclip

amansoori
02-09-2006, 11:15 PM
ok thank you. I firgured out what my problem was.

now it works:

class Lines_obj extends MovieClip implements Shapes_obj
{
var line_mc:MovieClip;
var myPos;
public function Lines_obj(passed:MovieClip){
trace("yes it does");
line_mc = passed;
myPos = new Point_obj();

}
..
.
.
.
.
.