There had been some hints that with javascript in director there might possibly be a chance to use unicode in director.


Thomas Higgins, 7.1.04:

Lingo strings do not support Unicode so that's why you're likely having
trouble using Flash assets to render your unicode strings. Once Lingo
touches 'em you're hosed... But wait... There's more! You'll have to wait
for Christmas though, sorry!


Mark Jonkman, 12.2.04:


JS is unicode under the hood, so you get some "quasy" unicode handling (until you go to display - but if your display is a Flash sprite, you might just get away with the unicode remaining intact).


My plan went along similar lines. Translate my text manager to js, employ a bunch of flash sprites for output and input ( with the commonplayer set for minimal performance hit ) and voila, localizing projects to more demanding languages like thai, farsi, etc. would be much less intimidating...


Well, as of now the results look disappointing. In fact I have not found any indication that director's js supports unicode at all.


What follows is a longish tale of failure and a lame solution to at least tunnel unicode through directors realm.



I took my examples from the "anyone can be provincial!" page at <http://www.trigeminal.com/samples/provincial.html> and my first try was copy and paste. I didn't really expect the message window in javascript mode (all these experiments were javascript only) to display unicode and it didn't.


So I read the file with fileIO to a var and passed that via sendsprite() to a flash sprite for display. All the "non-western" characters showed as question marks, exactly as they did in the messWin. The next attempt went via _globals, same result.

OTOH, reading the file to a var in flash and then feeding it to the very same function for display worked fine and showed the text intact. My suspicion fell on the fileIO xtra.

Anyway, since I now had the data intact in that flash sprite I proceeded by pulling them up to directors javascript and then pass them to another flashsprite. The commonplayer brought to many crashes. So I tried it like

function test() {
  dsp=sprite(5);
  dsq=sprite(6);

  dtxt = dsp._root.sometext;
  dsq.setText( dtxt );
}

and this failed too, Question marks.

What about passing unicode strings packaged in arrays? js can access actionscript arrays, but not the other way. Similar, js accessing one flash sprites array and then just passing it to the other flash sprite won't do since its out of scope for the second flash. Therefore each flash sprite should supply its own array and js has to copy the data:


function test2() {


  dsp=sprite(5);
  dsq=sprite(6);

arrdsq = dsq.newObject( "Array" );

arrdsq.push ( dsp.getPackagedData().pop() );

dsq.setPackagedData( arrdsq );

}

Question marks. This about settles it. Both push() and pop() are actionscript methods, js only makes the two objects meet and passes the value. Even with javascript it appears that director strips unicode strings on assignment.


Ok, And after this long and disappointing narration here comes the only safe channel for unicode data from one flash sprite to another which I could make work: as an array of integers.


The flashs have these functions:



function getArrOfCharCodes(aStr){
        arr = new Array();
        for (i=0;i<aStr.length;i++){
                arr.push(aStr.charCodeAt(i));
        }
        return arr
}

function setArrOfCharCodes(arr) {
        var aStr="";
        for (i=0;i<arr.length;i++){
                aStr += String.fromCharCode(arr[i]);
        }
        setText(aStr);
}

function setText(aStr) {
        myTextInstance.text = aStr;
}


and in director :





function passData(){


  dsp=sprite(5);
  dsq=sprite(6);

  // arrsometext has been prepared by getArrOfCharCodes(aStr)
  arr = dsp._root.arrsometext;
  arrdsq = dsq.newObject( "Array" );

  // werte rueberheben
  for (i=0;i<arr.length;i++) {
    arrdsq.push( arr[i] );
  }

dsq.setArrOfCharCodes( arrdsq );

}


Hmm. I just hope someone finds a better way.



daniel plaenitz




[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]

Reply via email to