Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Flash Cards, Continued

Status
Not open for further replies.

bsquared18

Technical User
Jun 10, 2001
329
US
Hi,

Kenneth Kawamoto was kind enough to provide code for a random flashcard setup. See
I added a button to flashcard #1 to try to go from that flashcard to another frame where the answer for the flashcard would be (I arbitrarily used frame 5 to test the action, but in actuality the frame would be beyond the 32 frames dedicated to the flashcards).

My added code is shown as the first couple of lines of code below. When the button is pressed, nothing happens. I assume it has something to do with the other code. Is there a way to make the two sets of code work together?

Any help would be greatly appreciated.

Also, once one gets to the answer screen, what would be the button command to take the user back to the random screen they just left?

Thanks! Bill

// ActionScript 2
this.ans_button_1.onPress = function () {
gotoAndStop(5);
};
//Above is supposed to send action to frame 5
var frames:Array = [2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22,
23, 24, 25,
26, 27, 28, 29, 30, 31];
// Nrs. above are second frame to next to last frame.
stop();
//
this.button.onPress = function() {
var frameNumber:Number;
var n:Number = this._parent.frames.length;
if (n) {
var randomIndex:Number = Math.floor(Math.random()*n);
frameNumber = this._parent.frames.splice(randomIndex, 1);
} else {
frameNumber = 32;
//Nr. above is last frame.
}
this._parent.gotoAndStop(frameNumber);
};

//
 
Is your button called "ans_button_1"? If so it won't work as you're telling ans_button_1 to gotoAndStop at frame 5 on press. There's no frame 5 in ans_button_1, right? If you want to send the main timeline to frame 5, you have to do like this:
[tt]//
this.ans_button_1.onPress = function () {
this._parent.gotoAndStop(5);
};
//[/tt]
Remember this is AS2 - its scoping is not loose like in AS1

As for the 2nd part of your script, your array looks dodgy to me.
You can do:
[tt]//
var frames:Array = [];
for (var i = 2; i<=31; i++) {
frames.push(i);
}
//[/tt]
Saves you lot of typing too!
As long as your button is called "button" it will take you to a random frame specified in the array "frames".

Kenneth Kawamoto
 
Kenneth (and anyone else who wants to chime it),

I replaced my code with yours, but still nothing happens when I run test movie, flip through the random flashcards until I get to number 1, and then press the ans_button_1 button. Any other suggestions?

Thanks!

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top