|
-
Senior Member
how can i get the value from a function
how can i get the value from a function? this code makes my hero(commander) move to the last place the mouse clicked. I want to see the value of "secondclick" after it is assigned to my movie clip (hero ,commander, ect.).
Code:
function select(obj) {
secondclick = 0;
tab = false;
obj.onPress = function() {
createEmptyMovieClip("square_mc", 0);
square_mc.lineStyle(1, 0x00FF00);
square_mc.moveTo(0, 0);
square_mc.lineTo(0, 100);
square_mc.lineTo(100, 100);
square_mc.lineTo(100, 0);
square_mc.lineTo(0, 0);
secondclick++;
};
onEnterFrame = function () {
stoper = Math.round(obj._x-_root.ldx);
if (tab == true) {
obj._rotation = Math.atan2(_root.ldy-obj._y, _root.ldx-obj._x)/Math.PI*180+90;
xw = Math.sin(obj._rotation*(Math.PI/180))*8;
yw = Math.cos(obj._rotation*(Math.PI/180))*8*-1;
obj._x += xw;
obj._y += yw;
}
if (stoper>=-3 && stoper<=3) {
tab = false;
}
hie = obj._height;
wie = obj._width;
square_mc._x -= (square_mc._x-(obj._x-(wie/2)-.5));
square_mc._y -= (square_mc._y-(obj._y-(hie/2)-.5));
square_mc._width = 2+(obj._width);
square_mc._height = 2+(obj._height);
};
}
onMouseDown = function () {
_root.ldx = _root._xmouse;
_root.ldy = _root._ymouse;
_root.tab = true;
};
select(_root.commander);
select(_root.commander2);
i just want to know a way to see the value of "secondclick" from a dynamic text feild, if possible.
CEO OF
-
by not using the "var" keyword, you're scoping "secondclick" to the timeline its defined - i assume root. normally this is a (mildly) bad thing, but in this case it makes things a bit easier.
if you have a dynamic textfield with the variable "secondclick" it'll automatically do it.
adding the following line should demonstrate that
Code:
createTextField("display",this.getNextHighestDepth(),0,0,200,20).variable="secondclick";
-
Senior Member
thanks alot. I now understand what you mean by not using "var" keyword. Now all the variables are root. how can i make it so there local? thanks for the help.
CEO OF
-
if both these conditions are satisfied, the variable's local:
1. you say "var".
2. it's defined within function curlies.
that's it. it's actually called "function scope", and the difference isnt so much pathing but memory - local variables exist only for the time teh function is executing. the bit that was roughest for me to get my head around was that local's take precedence over globals, within that scope - which of course makes sense, but i was looking at globals as somehow more 'powerful'.
e.g., in a timeline
Code:
var A="global"; // note that the use of "var" outside a function call doesnt do anything - try it either way
function(){
var A="local";
trace(A+":"+_level0.A);}.call()
function(){
A="local";
trace(A+":"+_level0.A);}.call()
last thing - i don't use multiple timelines, but i believe that each timeline has its own scope additionally - as if it were a separate file.
hth, gl
Last edited by moagrius; 02-24-2006 at 06:01 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|