A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Simple Class Error.

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    55

    resolved [RESOLVED] Simple Class Error.

    Hey guys, whats goin on.

    I started to mess up with classes to see how they work, and I'm having some trouble.

    I'm trying to do a class where the user gives an array, and a number. The result is a trace of random X numbers, according to the number the user requested. If he/she types 3, the class gives 3 numbers.

    It works nice, but when I try to put an sort(Array.NUMERIC), i get this error:

    PHP Code:
    TypeErrorError #1034: Type Coercion failed: cannot convert undefined to Function.
        
    at Array$/_sort()
        
    at Array/http://adobe.com/AS3/2006/builtin::sort()
        
    at shuffle/doshuffle()
        
    at shuffle_fla::MainTimeline/frame1() 

    This is my class so far:

    PHP Code:
    package  {
        
        public class 
    shuffle {
            private var 
    _array:Array = [];
            private var 
    _array2:Array = [];
            private var 
    _number:Number = new Number();
            
            public function 
    doshuffle(Array, Number) {
                
    _array = Array;
                
    _numberNumber;
                
    _number= Array.length _number;
                while (
    _array.length _number) {
                    
    _array2.push(_array.splice(Math.round(Math.random() * (_array.length 1)), 1)[0]);
                }
                
    _array2.sort(Array.NUMERIC);
                
    trace (_array2);
            }
            
        }


    In my .FLA file, I got this:


    PHP Code:
    import shuffle;

    var 
    go:shuffle = new shuffle();

    var 
    testarray:Array = [];
    for (var 
    i:Number 050i++){
        
    testarray.push(i);
    }

    go.doshuffle(testarray6); 

    I believe it must be some stupid error of my part, but I can't solve it.
    Any help is greatly appreciated.
    Last edited by Guilhermedidi; 04-05-2011 at 04:04 PM.

  2. #2
    Member
    Join Date
    Mar 2009
    Location
    Brooklyn, NY
    Posts
    77
    At first glance it looks like you're using flash's reserved names for your function.

    Instead of:
    PHP Code:
    public function doshuffle(Array, Number) {
                
    _array = Array;
                
    _numberNumber;
                
    _number= Array.length _number
    Try:
    PHP Code:
    public function doshuffle(_array:Array, _number:Number) {
                
    _number_array.length _number
    Array and Number are words that flash will get mad at you for if you try to make them variable names. So instead, we're now saying variable _array is an Array and variable _number is a Number
    Break it until it works.

  3. #3
    Member
    Join Date
    Oct 2010
    Posts
    55
    sweet, cess, it worked!

    im just starting with classes, i know i could make some weird error, stupid me.

    thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center