Flasher Archive

[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]


Subject: Re: FLASH: controlling random
From: Markus Gut
Date: Tue, 14 Mar 2000 04:05:26 GMT

Hi Matt

> this may be a dumb question, but...
There are no dumb questions.

> Is there a way to use the random function so as to assure that the same
> pictures don't get displayed twice?
Yes, there is.

> In other words, say I have 10 symbols, "pic1" through "pic10". When a
> button is clicked, I want the visible of one of the 10 symbols set to
true.
> This much I can handle.
>
> But I then want to guarantee that once a picture has been displayed, it
> will in effect be removed from the "random" pool, so that it can't be
> displayed again, and once they've all been displayed the show ends.
> Thepictures will be displayed one at a time. Thanks!
>
> MAtt

I had to do that some months ago for some kind of quiz. A pool of 25
questions
were asked in a random order, but no question twice.

In the first frame of a MC with the instance name "playlist" I had the
following
action script (stop action in the second frame):

Comment: ------------------------------------------
Comment: Copyright (c) 1999 Markus Gut
Comment: markusatrun [dot] ch
Comment: ------------------------------------------
Set Variable: "listname" = "entry"
Set Variable: "entries" = 25
Comment: ------------------------------------------
Comment: Initialize 'playlist' variables:
Comment: listname1 = 1 etc.
Comment: ------------------------------------------
Set Variable: "i" = 1
Loop While (i <= entries)
Set Variable: listname & i = i
Set Variable: "i" = i + 1
End Loop
Comment: ------------------------------------------
Comment: Swap entries of list randomly
Comment: ------------------------------------------
Set Variable: "i" = 1
Loop While (i <= entries * 2)
Comment: Select which two entries to swap next
Set Variable: "swap1" = random(entries) + 1
Set Variable: "swap2" = random(entries) + 1
Comment: Back up current values
Set Variable: "backup1" = Eval ( listname & swap1 )
Set Variable: "backup2" = Eval ( listname & swap2 )
Comment: Swap entries
Set Variable: listname & swap1 = backup2
Set Variable: listname & swap2 = backup1
Set Variable: "i" = i + 1
End Loop


This code will generate a bunch of variables. If "listname" is set
to "picture" and "entries" is set to 10 (at the top of the script),
you'll get something like this:
picture1=7
picture2=4
picture3=5
picture4=2
picture5=10
picture6=6
picture7=1
picture8=9
picture9=3
picture10=8

If you want to show ten pictures, one after the other, put each one
into its own keyframe of another MC (called "pictures"). Some kind
of trigger event (another MC with a certain lenght of delay or a button
action) could include the code to show the next picture...

Begin Tell Target ("/pictures")
Go to and Stop (/playlist:picture&i)
End Tell Target

Where "i" is the number of the next question (in regular order 1..2..3...)

HTH
Markus



flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flashforward2000 and The Flash Film Festival
"The World�s Premier Flash Solutions Conference and Expo"
March 27-29, Nob Hill Masonic Center, San Francisco, California

-Register before Feb 25 and save $200!!-- www.flashforward2000.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpatchinwag [dot] com


Replies
  FLASH: controlling random, Matt Spiegler

[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]