Solved

how do you shuffle an Array in AS3

Posted on 2008-10-22
3
2,903 Views
Last Modified: 2013-11-11
how do you shuffle an Array in AS3.
is it even possible with AS3?
0
Comment
Question by:greeneel
3 Comments
 
LVL 37

Expert Comment

by:CyanBlue
ID: 22783071
What do you mean by shuffle???

CyanBlue
0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 22783201
I think this what you want,


following code works for both AS2 and AS3 without any change..
var myArray = [0,1,2,3,4,5,6,7,8,9];
 
trace("before:"+myArray);
myArray = myArray.sort(Randomise);	
trace("after:"+myArray);
 
function Randomise(a, b):Number {
	var num:Number = Math.round(Math.random()*2)-1;
	return num;
}

Open in new window

0
 
LVL 11

Author Comment

by:greeneel
ID: 22785226
thx alot
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question