LOGIN Don't have an account yet?   Register

Forgot password?
 

target of assignment must be a reference value

  • avatar
    Ammy
    on 23/6/11
    I don't know how to fix this error - 1105: Target of assignment must be a reference value.
    Here's my code:

    public static function countInstances(param1:String, param2:String) : int
    {
    var _loc_3:int = -1;
    var _loc_4:int = -1;
    do
    {

    ++_loc_4 = param1.indexOf(param2, ++_loc_4);
    _loc_3++;
    }while (++_loc_4 != -1)
    return _loc_3;
    }
  • avatar corneliu.chitanu
    on 27/6/11
    Hello Ammy,

    Bassically, you can't do this:
                    
    var a:Number;
    ++a = 3;
    
                    
    That's what you do here:
                    
    ++_loc_4 = param1.indexOf(param2, ++_loc_4);
    
                    
    What this does is assign a value (param1.indexOf(param2, ++_loc_4)) to another value. You must know that this expression:
                    
    a++;
    //or 
    ++a;
    
                    
    increments the variable and returns a value. The ++a returns the updated value, after it's incremented and a++ returns the value before it's incremented. Anyway, you can't assign a value to another value. You must assign a value to a reference, which would be a variable name. Your algorithm is not good anyway. This is what you need:
                    
    var str : String = "A String in another String";
    
    trace(str.split('String').length - 1); //this counts the number of appearances of the 'String' in the str string
    
    trace(str.split(new RegExp("IN", "gi")).length-1); //this counts the number of appearances of the "IN" string in the str string, but it will be case insensitive
    
                    


    Last edit: on 27/6/11

rss Subcribe to topic RSS

Post a comment

Please login to join the discussions. Don't have an account? Register (it takes 30 seconds)

This week's featured product

Store Locator

This cool AJAX application will enhance your website by showing your stores' locations. You can also display an image and a short description so your users know exactly where to find your business.

Become a premium member

premium membership Flabell and Themesbell membership provides users with the ability to download any of our components for Adobe Flash and website themes for free, during an entire year.
read more