0

im new to stackoverflow, so i hope im doing everything right here ^^

So to my Question/Problem:

Im working with Flash CC and made a small HTML5 Canvas Animation. In this Animation there is a Textfield where I want to load text from a file/database. Is this possible? I assume that I have to use javascript/json for that bec Flash CC Canvas is working with that. But can I code it directly in Flash (in the Actions Panel) or do I have to open the js-output file and put my code there? And are there any examples of that case?

Second, and a more specific case of that above, I want to load a specific text into my textfield for example:

lets say I have a text in 3 languages (english, italian, french). so I send a variable, where I state which language I want (var = eng;) and the correct text is loaded (from the file or database) to the textfield.

I hope everything is understandable (sry im not a native speaker)

Thanks in advance for any help/tips

Maki
  • 11
  • 4

1 Answers1

0

You can code that interaction directly into the .fla file if you like.
Here is a simple example that you can play around with:

  1. Open a new blank HTML5 Canvas Document in Flash
  2. Create a text field and button and give them the instance names of text_box for the text box and btn for the button.
  3. paste the following code onto frame 1 on the timeline:

    //Variables
    var count = 0;
    //Make browser listen for a mouse click on the button
    this.btn.addEventListener("click", fnCycleLang.bind(this));
    
    function fnCycleLang()
    {
     if(count == 0){
        this.text_box.text = "Hello World!"; //this actually changes the text in the text box
        count ++;//this adds 1 to the count
    }
    else if(count == 1){
        this.text_box.text = "Bonjour Le Monde!";
        count ++;
    }
    else if(count == 2){
        this.text_box.text = "Ciao Mondo!";
        count = 0;
    }
    }
    

When you publish the .fla to HTML5 you should be able to click the button to cycle through the different languages. This way may be a but code intensive but it depends on how much text you are going to need to swap around. This would be fine for something like some menu items. Anything with a lot of text you would probably be better off not using flash to author it for you.

Malco
  • 352
  • 6
  • 18
  • Hey Malco, thanks alot for that. But, is it also possible to get the textes "Hello World", "Ciao Mondo!" etc. from a file (like xml) or a database? – Maki May 27 '15 at 08:18
  • Check out this question here. [link](http://stackoverflow.com/questions/196498/how-do-i-load-the-contents-of-a-text-file-into-a-javascript-variable) – Malco May 27 '15 at 13:04
  • The answers in the above link do a better job explaining it than I could. The only thing to remember is that when you are working in a HTML 5 Canvas document, flash is outputting pretty much only JavaScript so most anything you could do in a separate .js you can do on a frame in flash. Just be careful about variable scope as any thing you write will be nested inside the different frame functions on output. – Malco May 27 '15 at 13:10
  • Ok, i see. Thanks for the answer :) – Maki May 27 '15 at 13:56