PDA

View Full Version : function inparameters used later



Zahmet
July 10th, 2007, 06:02 AM
function stick(btnname) {
if (current_btn != btnname) {
eval(current_btn).gotoAndPlay("out");
}
current_btn = btnname;
eval(current_btn).gotoAndStop("down");
}

I belive this would have worked in AS2, but I want to use AS3 and just wonder if there is anything similar to eval?

mathew.er
July 10th, 2007, 07:16 AM
Thats because eval was removed in AS3, you would want to pass reference to the MCs instead of string names and use those without the eval or use associative arrays to access the MCs e.g. this[current_btn].gotoAndPlay("out");

CarlLooper
July 10th, 2007, 07:26 AM
I haven't researched this fully but the "is" operator can be used to determine the type of object passed to it and while I haven't been able to find it in the docs I believe there is some sort of "reflection" API which enables one to extract other information about an object, eg. it's identifier.

If only I could find where I read about it ...

CarlLooper
July 10th, 2007, 07:29 AM
Found it:

flash.utils.describeType

Carl

Zahmet
July 10th, 2007, 07:37 AM
var current_btn = test_mc;

test_mc.buttonMode = true;
test_mc.addEventListener(
MouseEvent.MOUSE_OVER,
function(evt:MouseEvent):void {
test_mc.gotoAndPlay("over");
}
);
test_mc.addEventListener(
MouseEvent.MOUSE_OUT,
function(evt:MouseEvent):void {
test_mc.gotoAndPlay("out");
}
);
test_mc.addEventListener(
MouseEvent.MOUSE_DOWN,
function(evt:MouseEvent):void {
stick("test_mc");
}
);

ovrigt_mc.buttonMode = true;
ovrigt_mc.addEventListener(
MouseEvent.MOUSE_OVER,
function(evt:MouseEvent):void {
ovrigt_mc.gotoAndPlay("over");
}
);
ovrigt_mc.addEventListener(
MouseEvent.MOUSE_OUT,
function(evt:MouseEvent):void {
ovrigt_mc.gotoAndPlay("out");
}
);
ovrigt_mc.addEventListener(
MouseEvent.MOUSE_DOWN,
function(evt:MouseEvent):void {
stick("ovrigt_mc");
}
);

ramverk_mc.buttonMode = true;
ramverk_mc.addEventListener(
MouseEvent.MOUSE_OVER,
function(evt:MouseEvent):void {
ramverk_mc.gotoAndPlay("over");
}
);
ramverk_mc.addEventListener(
MouseEvent.MOUSE_OUT,
function(evt:MouseEvent):void {
ramverk_mc.gotoAndPlay("out");
}
);

ramverk_mc.addEventListener(
MouseEvent.MOUSE_DOWN,
function(evt:MouseEvent):void {
stick("ramverk_mc");
}
);

function stick(btnname) {
if (current_btn != btnname) {
this[current_btn].gotoAndPlay("out");;
}
current_btn = btnname;
this[current_btn].gotoAndStop("down");
}

This is what im trying, its just movieclip buttons that have animations when you go over, out or press them, but I cant get the "stick" to work, since when I click a button I want it to stay in the "down" state and not play the out movie, exept that I want it to play the out of the last button that was pressed so if i click test I want it in the down state, if I then press "ramverk_mc" I want that in downstate and I want the oldbutton (test) to do its out movie.

I think the code is correct for this exept that I get an error:

TypeError: Error #1010: A term is undefined and has no properties.
at alternativutanflikar_fla::MainTimeline/stick()
at MethodInfo-13()

Charleh
July 10th, 2007, 07:42 AM
var current_btn = test_mc;

test_mc.buttonMode = true;
test_mc.addEventListener(
MouseEvent.MOUSE_OVER,
function(evt:MouseEvent):void {
test_mc.gotoAndPlay("over");
}
);
test_mc.addEventListener(
MouseEvent.MOUSE_OUT,
function(evt:MouseEvent):void {
test_mc.gotoAndPlay("out");
}
);
test_mc.addEventListener(
MouseEvent.MOUSE_DOWN,
function(evt:MouseEvent):void {
stick("test_mc");
}
);

ovrigt_mc.buttonMode = true;
ovrigt_mc.addEventListener(
MouseEvent.MOUSE_OVER,
function(evt:MouseEvent):void {
ovrigt_mc.gotoAndPlay("over");
}
);
ovrigt_mc.addEventListener(
MouseEvent.MOUSE_OUT,
function(evt:MouseEvent):void {
ovrigt_mc.gotoAndPlay("out");
}
);
ovrigt_mc.addEventListener(
MouseEvent.MOUSE_DOWN,
function(evt:MouseEvent):void {
stick("ovrigt_mc");
}
);

ramverk_mc.buttonMode = true;
ramverk_mc.addEventListener(
MouseEvent.MOUSE_OVER,
function(evt:MouseEvent):void {
ramverk_mc.gotoAndPlay("over");
}
);
ramverk_mc.addEventListener(
MouseEvent.MOUSE_OUT,
function(evt:MouseEvent):void {
ramverk_mc.gotoAndPlay("out");
}
);

ramverk_mc.addEventListener(
MouseEvent.MOUSE_DOWN,
function(evt:MouseEvent):void {
stick("ramverk_mc");
}
);

function stick(btnname) {
if (current_btn != btnname) {
this[current_btn].gotoAndPlay("out");;
}
current_btn = btnname;
this[current_btn].gotoAndStop("down");
}

This is what im trying, its just movieclip buttons that have animations when you go over, out or press them, but I cant get the "stick" to work, since when I click a button I want it to stay in the "down" state and not play the out movie, exept that I want it to play the out of the last button that was pressed so if i click test I want it in the down state, if I then press "ramverk_mc" I want that in downstate and I want the oldbutton (test) to do its out movie.

I think the code is correct for this exept that I get an error:

TypeError: Error #1010: A term is undefined and has no properties.
at alternativutanflikar_fla::MainTimeline/stick()
at MethodInfo-13()

Er shouldn't you just be accessing the object via the reference passed in - what is 'this'? Is it an array of buttons?

Surely you want

function stick(btnname) {
if (current_btn != btnname) {
current_btn.gotoAndPlay("out");;
}
current_btn = btnname;
current_btn.gotoAndStop("down");
}

and you want to pass the buttons in as references not strings

It should not be stick("button_name")

It should be stick(button_reference)

i.e.

stick(evt.target);


Also isn't it a good idea to explcitly type your vars? i.e.

var something:Number;
var somethingElse:MovieClip;

etc?

Zahmet
July 10th, 2007, 07:44 AM
I tested that, just get:

TypeError: Error #1006: value is not a function.
at alternativutanflikar_fla::MainTimeline/stick()
at MethodInfo-13()

Charleh
July 10th, 2007, 07:50 AM
Post the whole code again...that error message doesn't seem to make sense in the context of the code I can see - it's saying that stick() isn't a function..

Zahmet
July 10th, 2007, 07:54 AM
Thanks for the string thing, I got it working better now, its behaving ok :P

Think I did some logial fault that should resolve once I get into them but otherwise they do ok now, Thanks for the help