A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: text splicing prob...

  1. #1
    Junior Member
    Join Date
    Mar 2002

    text splicing prob...

    i'm making a game in flash 5 and i want to create a text effect in such away that a variable can be displayed in the form of a series of video clips beside each other each with a png of a letter inside them.

    to do this i want to have some code that will split
    message = "hello"
    in to
    ch1 = "h"
    ch2 = "e"
    ch3 = "l"
    ch4 = "l"
    ch5 = "o"

    i know there's someway to do this with arrays but i'm not too sure. I quite experienced with actionscript but it's the most advanced launguage i know and arrays is something new to me.

  2. #2
    Welcome to flavour country
    Join Date
    Sep 2000
    You can write a method for the String object which will do this:

    String.prototype.stringToArray = function(){
    var temp = new Array();
    for(var i=0;i<this.length;i++){
    temp[i] = this.charAt(i);
    return temp;
    You could then use it like so:

    message = "hello";
    myStringArray = message.stringToArray();
    The variable myStringArray is now an array of the letters in the variable message.

    Hope this helps.

  3. #3
    Senior Member
    Join Date
    Aug 2001
    there is already a method called split;

    str = "hello";
    arr = str.split("");


  4. #4
    Junior Member
    Join Date
    Mar 2002
    ok, thanks for that =>

    i manages to split up the variables the way i want but i've realised the next thing i want to do is somewhat more confusing than i thought

    within a instance called text there are 26 movie clip instances each with a letter from the alphabet inside them and are all named A B or C ect.

    in each clip i wrote a line of code
    w = 17
    were 17 is the width of the letter

    i want to be able measure the total width of all the letters in the message so i can find out were to place the first letter movie clip so that the message will appear in the centre of the screen.

    then basicly place every other letter on the screen by duplicating the letter movie clips from the inside the text instance. the only way i found to do this is by writting enourmous amounts of repedive code. I'm sure there has to be a somewhat easier way =/

    thanks in advance to anyone who at least tries to answer this

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