PDA

View Full Version : Is this possible??



leahgrace
May 20th, 2005, 04:25 PM
I'm trying to create a custom function called "turnOn" with (name) as the function variable(?is that how I should refer to it?). This function is an if/else statement that will be called through an on(release) button event.

The if has a bunch of && conditions, if true gotoAndStop on frame two of specified movie clip. But I'm trying to write it put it in a function so that I don't have to put all this code on every single button. So i'm using the "name" function variable to specify the movieclip that should be affected by button action, but it won't work. Is it possible to do this? What I have now is like this:


function turnOn (name) {
if (polPlan_mc._currentframe == 1 && baseDB_mc._currentframe == 1 && polNum_mc._currentframe == 1 && paidTo_mc._currentframe == 1 && addBen_mc._currentframe == 1 && dividend_mc._currentframe == 1 && insured_mc._currentframe == 1 && lifeDB_mc._currentframe == 1 && netCV_mc._currentframe == 1 && polCV_mc._currentframe == 1 && polDate_mc._currentframe == 1 && premium_mc._currentframe == 1 && summary_mc._currentframe == 1 && totalDB_mc._currentframe == 1) {
name+.gotoAndStop(2);
} else {
polPlan_mc.gotoAndStop(1);
polNum_mc.gotoAndStop(1);
baseDB_mc.gotoAndStop(1);
paidTo_mc.gotoAndStop(1);
addBen_mc.gotoAndStop(1);
dividend_mc.gotoAndStop(1);
insured_mc.gotoAndStop(1);
lifeDB_mc.gotoAndStop(1);
netCV_mc.gotoAndStop(1);
polCV_mc.gotoAndStop(1);
polDate_mc.gotoAndStop(1);
premium_mc.gotoAndStop(1);
summary_mc.gotoAndStop(1);
totalDB_mc.gotoAndStop(1);
name+.gotoAndStop(2);
}
}

and then on the button instance I have


on (release) {
_root.turnOn ("insured_mc")


obviously something is wrong because it's not working, and I'm guessing it has to do with the fact that .gotoAndStop(2); isn't a string and I can't just add "insured_mc" to it, but is there a way for me to do this so that I don't have to put this function code on every single button?

mprzybylski
May 20th, 2005, 05:43 PM
try this:



function turnOn(name:MovieClip):Void {
if (polPlan_mc._currentframe == 1 && baseDB_mc._currentframe == 1 && polNum_mc._currentframe == 1 && paidTo_mc._currentframe == 1 && addBen_mc._currentframe == 1 && dividend_mc._currentframe == 1 && insured_mc._currentframe == 1 && lifeDB_mc._currentframe == 1 && netCV_mc._currentframe == 1 && polCV_mc._currentframe == 1 && polDate_mc._currentframe == 1 && premium_mc._currentframe == 1 && summary_mc._currentframe == 1 && totalDB_mc._currentframe == 1) {
name.gotoAndStop(2);
} else {
polPlan_mc.gotoAndStop(1);
polNum_mc.gotoAndStop(1);
baseDB_mc.gotoAndStop(1);
paidTo_mc.gotoAndStop(1);
addBen_mc.gotoAndStop(1);
dividend_mc.gotoAndStop(1);
insured_mc.gotoAndStop(1);
lifeDB_mc.gotoAndStop(1);
netCV_mc.gotoAndStop(1);
polCV_mc.gotoAndStop(1);
polDate_mc.gotoAndStop(1);
premium_mc.gotoAndStop(1);
summary_mc.gotoAndStop(1);
totalDB_mc.gotoAndStop(1);
name.gotoAndStop(2);
}
}


and on ur button:

on (release) {
_root.turnOn(insured_mc);
}

virusescu
May 20th, 2005, 08:10 PM
What mprzybylski suggested is good practice, but you need to pass as a parameter the refference to an object.. and not a string.
If you need to use the _name of an instance.. wich is a string... you can obtain a refference to that instance by "evaluating" the string.
Short example. Considering you have an mc named box_mc in your stage.


function moveMcby5px (whatMC){
trace("Moving the mc named "+whatMC);
this[whatMC]._x += 5;
//or eval(whatMC)._x += 5;//but the first one is better.
}
moveMcby5px("box_mc");// now you can pass a string too

;)

EmeniusXp
May 20th, 2005, 10:15 PM
or you can simply user the path to the MC like:

this._parent[name].gotoAndStop(2);