PDA

View Full Version : Real Simple onPress Problem


MJWarren@Syr
07-14-2005, 03:42 PM
Im working in a component trying to make a simple action in an onPress. It must be somthing simple Im over looking. heres a bit of my code

public function drop() {
init();
children();
actions();

}

private function init() {

__width = _width;
if(_height<26)
__height = _height;
_xscale = 100;
_yscale = 100;
box._visible=false;

}

private function children() {
attachMovie("menu","menu",getNextHighestDepth());
attachMovie("leftEnd","leftEnd",getNextHighestDepth());
attachMovie("rightEnd","rightEnd",getNextHighestDepth());
attachMovie("_drop","_drop",getNextHighestDepth());
attachMovie("left_dropEnd","left_dropEnd",getNextHighestDepth());
attachMovie("right_dropEnd","right_dropEnd",getNextHighestDepth());
//attachMovie("blue","blue",getNextHighestDepth());
attachMovie("_arrowBox","_arrowBox",getNextHighestDepth());
attachMovie("_arrow","_arrow",getNextHighestDepth());

if(_y>(Stage.height-(_drop._height+menu._height))) {
_arrow._rotation=180;
down=false;
}


}

private function actions() {

_arrow.onPress = function() {
trace(down);
trace(leftEnd._x);
if(down==true) {
left_dropEnd._x=leftEnd._x;
left_dropEnd._y=menu._y+menu._height;
_drop._x=left_dropEnd._x;
_drop._y=left_dropEnd._y;
right_dropEnd._x=_drop._x;
right_dropEnd._y=_drop._y;
}
else if(down==false) {
left_dropEnd._x=leftEnd._x;
left_dropEnd._y=menu._y-left_dropEnd._height;
_drop._x=left_dropEnd._x;
_drop._y=left_dropEnd._y;
right_dropEnd._x=_drop._x;
right_dropEnd._y=_drop._y;
}


};
}

the actions i give in the onPress just dont work, both the traces display undefined. I just cant see what the problem is. anyone ever have similar problems? any help would be great.

-tron

sleekdigital
07-14-2005, 04:00 PM
Probably a scope problem. Remeber, the onPress in applied to _arrow, so all the code in the onPress will be in that scope and "this" will refer to _arrow. You also have access to any variables local to the "actions" function. So if you want to refer to the instance of the class you are working on there, you can say "me = this" just before the onPress definition then use "me" inside the onPress.. for example trace(me.down)

MJWarren@Syr
07-14-2005, 04:11 PM
yes it was a scope problem but instead of this i need to use _parent, thank you very much, i hate getting stuck on simple problems like this.

-mike