Search code examples
actionscript

Property not found on String


So i am trying to make a word jumlbe sort of program but i am running into some difficulties with the function for shuffelling the words

So i tried:

function klikk(evt){
var i:int = 0;
var ordet:String = inntastetOrd;
var lengde:int = ordet.length;
var tall:int = 0;
var karakter:String;

for(i=0;i<ordet.length; i++)
{
    tall = Math.random() *ordet.length;
    karakter = ordet[tall];
    ordet[i] = ordet[tall];
    ordet[tall] = karakter;
}

But i am getting: "Error #1069: Property "some value" not found on String and there is no default value."

Thanks for help!


Solution

  • If you want to chose a letter in a String, you need to transform this String into Array with the split method.

    For example:

    var letters:String = "word";
    trace(letters[2]); // Error #1069
    var a:Array = letters.split(""); // w,o,r,d
    trace(a[2]); // r