LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




ReplyREPLY THREAD
 
Thread Tools Display Modes
  #1  
Old 03-23-2011, 02:18 AM
freaksarise freaksarise is offline
Registered User
 
Join Date: Nov 2004
Posts: 111
Rep Power: 9
freaksarise is on a distinguished road
Understanding Class: Assigning to MC is easy. How to use for array?

Hello all. I apologize for the cryptic title of this post but am not sure how to ask.

Allow me to explain:

1. If I needed to create a package, class, constructor function/method that is executed with each instantiation of a movieclip that includes it's link to the class, I am cool.

2. I have four arrays. Each need to have their values shuffled. I developed code that does just that but instead of keying the same block of code over and over, I would like to just say arrayName.shuffle();

I am not sure how to parse an array (which is not an MC/sprite) through a class.

This is what I am using to shuffle an array

Actionscript:
while (ChooseFromCollections.length > 0)
    {
        var rw_randomNumbr:Number = Math.floor(Math.random()*ChooseFromCollections.length);
        chosenCollections.push(ChooseFromCollections[rw_randomNumbr]);
        ChooseFromCollections.splice(rw_randomNumbr,1);
        trace(ChooseFromCollections);
        
    }
In the above I could swap the ChooseFromCollections hardcoded array name with a more dynamic variable that would allow any array to be passed through there.

But if I was passing the array to the above with the udpated dynamic variables, how would I pass it to? It's an array not a movieclip.

I would like to be able to add a new sprite to the stage and with that new sprite have it inherit a bunch of the functions and properties I will need.

This is my worst post over. i am just very confused and my sleeping pill has kicked in. I hope maybe some of this makes sense.

Thanks
Rich
__________________
Enjoy my music for free
http://www.FreaksArise.com

Last edited by FlashMove : 05-17-2011 at 03:23 AM
Reply With Quote
  #2  
Old 03-28-2011, 09:10 PM
freaksarise freaksarise is offline
Registered User
 
Join Date: Nov 2004
Posts: 111
Rep Power: 9
freaksarise is on a distinguished road
I apologize for my incredible confusion in my initial question but here is the answer. I will also post this as a new topic for others to use:

I was simply trying to work with ANY array by sending its values to ONE master function. In this case I have this shuffler I created.

Code:

var rwArray:Array = [1,2,3];
var chosenCollections:Array = new Array;

//pass the NAME of the array to the function

function rwShuffle(passedName:String)
{
	while (this[passedName].length > 0)
	{
	var rw_randomNumbr:Number = Math.floor(Math.random() * this[passedName].length);
	chosenCollections.push(this[passedName][[rw_randomNumbr]]);
	this[passedName].splice(rw_randomNumbr,1);
	
	}//close loop;
}

//Shuffle an array by sending the name of the array as a string
rwShuffle("rwArray");

//test the shuffle function by tracing the array updated within the shuffle function
trace (chosenCollections);
__________________
Enjoy my music for free
http://www.FreaksArise.com
Reply With Quote
  #3  
Old 05-17-2011, 12:46 AM
Scottae's Avatar
Scottae Scottae is offline
God Moderator
 
Join Date: Oct 2003
Location: United States
Posts: 6,532
Rep Power: 16
Scottae is on a distinguished road
Why don't you just use the sort method for Array?

Actionscript:
var arr:Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
function randomSort(item1:*, item2:*):Number {
	return Math.random() > 0.5 ? -1 : 1;
}
trace(arr);
arr = arr.sort(randomSort);
trace(arr);
__________________
Our greatest glory is not in never falling but in rising everytime we fall. - Confucius

Blog | Shared Items
Reply With Quote


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking symbol to custom class skitzer Flash CS3 / Flash 9 6 03-12-2010 02:20 PM
ways for movieclip inheriting class Isekream Actionscript 2.0 1 07-27-2006 02:00 AM
deleting Class resources wesm Flash MX 2004 1 01-31-2006 07:13 PM
Getting the class name/package at runtime Scottae Actionscript 2.0 3 01-26-2005 04:39 AM
as2 class questions Solari Flash MX 2004 7 10-11-2003 01:38 AM




All times are GMT. The time now is 12:49 PM.