PDA

View Full Version : Project help?


Jazzer
08-13-2008, 06:54 AM
Hi all. I'm about to attempt a simple project in Flash CS3 and I could use some pointers.

There's very little to it. Basically, I want to create a book which displays a random page when a button is pressed. I think I can create the 'movies' of the various pages opening but what I'm not sure about is 1) how to organise the project to keep it simple and 2) how to randomise the page movies and avoid repeats (important but not critical).

Any help would be much appreciated.

DiamondDog
08-13-2008, 07:39 PM
Sounds as though you'll need a way to generate a random ordering of the page numbers, without repeats.

There are probably lots of ways of doing that, but here's one (using AS3).

Assume there are nine pages, numbered 0 - 8 inclusive.

var pageNumbers = [0,1,2,3,4,5,6,7,8];

for(var p:int = 0; p<9; p++)
{
// pick the next page number by picking a random element from the 'pageNumbers' array
var posn:int = Math.floor(Math.random()*(pageNumbers.length));

// do what you want to do with that page number
trace(pageNumbers[posn]);

// remove that page number from the 'pageNumbers' array
pageNumbers.splice(posn,1);

}

Hope that helps a little.

Jazzer
08-15-2008, 06:49 AM
Fantastic! That gives me a real head start. Thanks ever so much.

Jazzer
08-19-2008, 11:06 AM
Okay, I'm still a little stuck trying to use this code with buttons.

How would I do the following:

Each time a button is pressed -- let's say it's instance name is random_btn -- I want to execute the code as posted, take that random number (0 to 9) and go to one of 10 different named frames -- we'll call them PageFrame 0 - 9.

DiamondDog
08-19-2008, 03:03 PM
There are probably lots of ways you could do this, and I doubt mine is the most efficient, but it seems to work OK.

Attached is a .fla containing a tiny demo, with this code on the first frame. Hope it helps.

var nextPage:Array; // will hold the page numbers, in random order
var pageNumbers:Array;

doRandomOrdering();
stop();

function doRandomOrdering():void // fill the 'nextPage' array with a random ordering of the pages
{
nextPage = new Array();
pageNumbers = [0,1,2,3,4,5,6,7,8,9];
for(var p:int = 0; p<10; p++)
{
// pick the next page number by picking a random element from the 'pageNumbers' array
var posn:int = Math.floor(Math.random()*(pageNumbers.length));

// put that page number into the 'nextPage' array
nextPage.push(pageNumbers[posn]);

// remove that page number from the 'pageNumbers' array
pageNumbers.splice(posn,1);
}
trace(nextPage);
} // end doRandomOrdering


myNextButton.addEventListener(MouseEvent.CLICK, doNextPage);

function doNextPage(e:MouseEvent)
{
// build the label of the next frame we're going to visit
var frameName:String = "PageFrame" + theNextPage().toString();
gotoAndStop(frameName);
}

function theNextPage():int
{
// returns the number of the next frame we're going to visit
if(nextPage.length == 0) // we've visited all the pages
{
doRandomOrdering(); // create a new random ordering of the pages
}

return(nextPage.shift()); // the first value in the 'nextPage' array

} // end nextPage

Jazzer
08-19-2008, 06:39 PM
You're a life saver! I think this is going to work perfectly for my little project. Thank you again.

Jazzer
08-21-2008, 07:27 PM
OK, the method described works beautifully. Unfortunately, I've hit a rather annoying but critical snag.

You see, in each of the frames I want to display a very simple movie. The movie contains nothing more than a series of PNGs imported from 3D Max that create an animation. I don't want the movie to loop so I put a 'stop ();' at the end frame. Sadly, doing so totally disables our 'myNextButton'.

Quicksilver_0
08-22-2008, 10:41 AM
OK, the method described works beautifully. Unfortunately, I've hit a rather annoying but critical snag.

You see, in each of the frames I want to display a very simple movie. The movie contains nothing more than a series of PNGs imported from 3D Max that create an animation. I don't want the movie to loop so I put a 'stop ();' at the end frame. Sadly, doing so totally disables our 'myNextButton'.

Ok, im not sure how your program is going, but maybe you can use a do while loop instead of a stop().

code:

do while(buttonhasbeenpressed != true) //or: do while(buttonhasbeenpressed == false)
{
//do nothing, or whatever you want
}


NOTE: buttonhasbeenpressed is a Boolean value which is true if a button has been pressed.


hope this helps somehow

Jazzer
08-22-2008, 11:00 AM
I daresay you're right but I wouldn't know how to implement it. All I really want to do is play the movie resident in the called frame once without terminating the original script.

Jazzer
08-22-2008, 11:24 AM
Now I think about it, is there a way of calling movies within certain frames instead of just placing them there? If so, I could use the original script to call numbered movies. That would be easy for me to implement.