PDA

View Full Version : Path Problem


nigeledge
04-02-2003, 07:40 AM
I've created a simple class... in the class I have a function which creates a button clip...
this.createButton = function()
{

_root.createEmptyMovieClip("button",300);
_root.button.lineStyle(0,0x000000,100);
_root.button.beginFill(0xE6E6DC,100);
_root.button.moveTo(20,35);
_root.button.lineTo(20,55);
_root.button.lineTo(100,55);
_root.button.lineTo(100,35);
_root.button.lineTo(20,35);
_root.button.endFill();

_root.button.onRelease = function()
{
// here's the problem.
pathToFunction.buttonClicked();
}

};
In the onRelease handler I want to call another function within the class... however... I can't get it to work. Basically, I don't know how to path reference it.

tg
04-02-2003, 01:31 PM
yes this is a tricky one...

so you have the following inside your class:


_root.button.onRelease = function()
{
// here's the problem.
pathToFunction.buttonClicked();
}



what you want to reference is this.buttonClicked(), but if you do, then 'this' refers to the button instead of the class.
and of course _parent doesn't work, cause that refers to the parent of the class.

so here is what you do.

in your class do this:

MyClass=function(){
this.tl=this;//creates a reference point to the class timeline
}
MyClass.buttonClicked=function(){
//some button clickie stuff here
};

//then on your button do:

MyClass.createButton=function(){
...
...
...
this.button.onRelease = function(){
// here's the problem.
this.tl..buttonClicked();
};
};


change your '_root' to 'this'.
that way your button is part of your class... if this wont work for your settup, you should be able to work something out along these lines...


of course if you use the code exactly as you have it written, with the class creating a button on the root timeline, then the path should be:

_root.instanceNameofMCWithClass.buttonClicked();

try either, try both.

nigeledge
04-03-2003, 03:39 PM
Thanks for your help... but now I'm more confused than ever. Sorry, but as my title says, I'm a flash idiot. :)

Ricod
04-03-2003, 03:51 PM
I think what tg is saying is : You need to 'tell' Flash where to find your buttonClicked() function. By using that first line : this.tl=this;//creates a reference point to the class timeline
you do exactly that. As it states in the comment. (everything after the //)

nigeledge
04-03-2003, 04:58 PM
I get that part... but if I call this.tl.buttonClicked()... it does not work because "this.tl" is outside of the method. I think what I'm confused about is making the button part of the class as tg suggested. I tried that and it wouldn't draw.