all groups > flash actionscript > december 2005 >
You're in the

flash actionscript

group:

attachMovie from MovieClip frame


attachMovie from MovieClip frame 300thnickattempt
12/29/2005 7:26:22 PM
flash actionscript:
Hi guys, I'm still a total idiot with Flash and I've ran into a problem. I have
a quiz game that I'm making that has a character in it that does a win, lose
and idle animation. I want to be able to call the win and lose animations only
once and then have it return to the idle animation once it reaches the last
frame of the win/lose movie clips. All animations are exactly 30 frames each.

I've tried to write a bunch of complex code to read what frame it's on and
check vs. the totalframes nad then make a call, but I'm running into just the
worst logistics with it so I want something simpler. So I went into the
moviecips themselves and attached this line of code to the last frame.

this.attachMovie("Idle1", "Idle1_mc", 1);

It's working, for the most part, but what's happenining is I can't replace the
clip that's running the win animation, rather the idle animation plays behind
it and the win one does not get replaced. I'm using a depth of 1 and I've been
using that from the main timeline all throughout my entire project with no
problems. It's always replaced the clip just fine. It's just that when I invoke
the same thing from the last (embedded) frame of the actual movie clip itself,
it does not replace what's been called from the main timeline. Is there
something really easy I'm missing because nothing's getting it to replace.

Below is my entire code, it's convoluted, but it's there in case you need more
background. I really hope posting it doesn't piss anybody off, but I've tried a
lot of things and sometimes people want to see the whole picture. I'll provide
anything else that's needed as well. This is off an actions layer I made and
controls the checking of the answers vs. the level of the game and also ties
the movieclip to follow a level meter, which is an invisible placeholder object
named CharPH. I've made all the lines relevant to my attachmovie problem stand
out.

function CharAni():Void {
LinMer.attachMovie("Idle1", "Idle1_mc", 1);
}

function CharMove() {
trace(CharPH._y);
if (z="up") {
if (x>y) {
x--;
} else if (z="down") {
if (x<y) {
x++;
}
}
}
if (x<45){ x = 45;}
if (x>333){ x = 333;}
_root.CharPH._y = x;

}

function CharCalc(ynow, ythen, zdir):Void {
x = ynow;
y = ythen;
z = zdir;
dir = "nothing";
trace("Calc Happened");
}

function checkanswer(a):Void {
clickable = "nogo";
if (_root.correctanswer == a) {
dir = "up";
RESULT.textColor = 0x00FF00;
RESULT.text = "CORRECT";
CharPH.LinMer.attachMovie("Win1", "Win1_mc", 1);
reload.level += 1;
if (reload.level == 11) {
reload.level = 10;
}
} else {
dir = "down";
CharPH.LinMer.attachMovie("Lose1", "Lose1_mc", 1);
RESULT.textColor = 0xFF0000;
RESULT.text = "INCORRECT";
reload.level -= 2;
if (reload.level<1) {
reload.level = 1;
}
}
}

function initialize():Void {
if (dir == "down") {
trace("initialize dir="+dir);
_root.CharCalc(_root.CharPH._y, _root.CharPH._y+64, "DOWN");
} else if (dir == "up") {
trace("initialize dir="+dir);
_root.CharCalc(_root.CharPH._y, _root.CharPH._y-32, "UP");
}
clearInterval(myTimer);
RESULT.textColor = 0x000000;
RESULT.text = "";
clickable = "go";
clearInterval(myTimer);
var Qran:Number =
Math.floor(Math.random()*_root["Questions"+(reload.level)].length-1)+1;
var Aranpos:Number = Math.floor(Math.random()*3)+1;
var AnswerPosition:Number = Math.floor(Math.random()*4)+1;
var DistractorVar:Number = Math.floor(Math.random()*2)+1;
_root.Question.text = _root["Questions"+(reload.level)][(Qran)];
if (AnswerPosition == 1) {
correctanswer = 1;
_root["Answer"+(AnswerPosition)].text =
_root["Answers"+(reload.level)][Qran];
_root.Answer2.text = _root["Distractors"+(reload.level)][0];
_root.Answer3.text = _root["Distractors"+(reload.level)][1];
_root.Answer4.text = _root["Distractors"+(reload.level)][2];
} else if (AnswerPosition == 2) {
correctanswer = 2;
_root["Answer"+(AnswerPosition)].text =
_root["Answers"+(reload.level)][Qran];
_root.Answer1.text = _root["Distractors"+(reload.level)][0];
_root.Answer3.text = _root["Distractors"+(reload.level)][1];
_root.Answer4.text = _root["Distractors"+(reload.level)][2];
} else if (AnswerPosition == 3) {
correctanswer = 3;
_root["Answer"+(AnswerPosition)].text =
_root["Answers"+(reload.level)][Qran];
_root.Answer1.text = _root["Distractors"+(reload.level)][0];
_root.Answer2.text = _root["Distractors"+(reload.level)][1];
_root.Answer4.text = _root["Distractors"+(reload.level)][2];
} else if (AnswerPosition == 4) {
correctanswer = 4;
_root["Answer"+(AnswerPosition)].text =
_root["Answers"+(reload.level)][Qran];
_root.Answer1.text = _root["Distractors"+(reload.level)][0];
_root.Answer2.text = _root["Distractors"+(reload.level)][1];
_root.Answer3.text = _root["Distractors"+(reload.level)][2];
}
// trace(correctanswer);
LEVEL.text = reload.level;
}
var clickable:String;
var ranpositions:Array = [0, 1, 2, 3];
var Questions1:Array = ["Question1a", "Question1b", "Question1c",
"Question1d"];
var Answers1:Array = ["Answer1a", "Answer1b", "Answer1c", "Answer1d"];
var Distractors1:Array = ["Distractor1a", "Distractor1b", "Distractor1c"];
var Questions2:Array = ["Question2a", "Question2b", "Question2c",
"Question2d"];
var Answers2:Array = ["Answer2a", "Answer2b", "Answer2c", "Answer2d"];
var Distractors2:Array = ["Distractor2a", "Distractor2b", "Distractor2c"];
var Questions3:Array = ["Question3a", "Question3b", "Question3c",
"Question3d"];
var Answers3:Array = ["Answer3a", "Answer3b", "Answer3c", "Answer3d"];
var Distractors3:Array = ["Distractor3a", "Distractor3b", "Distractor3c"];
var Questions4:Array = ["Question4a", "Question4b", "Question4c",
"Question4d"];
var Answers4:Array = ["Answer4a", "Answer4b", "Answer4c", "Answer4d"];
var Distractors4:Array = ["Distractor4a", "Distractor4b", "Distractor4c"];
var Questions5:Array = ["Question5a", "Question5b", "Question5c",
"Question5d"];
var Answers5:Array = ["Answer5a", "Answer5b", "Answer5c", "Answer5d"];
var Distractors5:Array = ["Distractor5a", "Distractor5b", "Distractor5c"];
var Questions6:Array = ["Question6a", "Question6b", "Question6c",
"Question6d"];
var Answers6:Array = ["Answer6a", "Answer1b", "Answer6c", "Answer6d"];
var Distractors6:Array = ["Distractor6a", "Distractor6b", "Distractor6c"];
var Questions7:Array = ["Question7a", "Question7b", "Question7c",
"Question7d"];
var Answers7:Array = ["Answer7a", "Answer7b", "Answer7c", "Answer7d"];
var Distractors7:Array = ["Distractor7a", "Distractor7b", "Distractor7c"];
var Questions8:Array = ["Question8a", "Question8b", "Question8c",
"Question8d"];
Re: attachMovie from MovieClip frame kglad
12/29/2005 8:30:58 PM
if you place your win and lose animations at the same depth (say depth 1 on the
_root timeline), you can then use:

_root.attachMovie("idle1","idle1",1);

on the last line of your win and lose animations.
AddThis Social Bookmark Button