A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Javascript to dynamic text - PLEASE HELP!!

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    12

    Javascript to dynamic text - PLEASE HELP!!

    For reasons which I won't bore you with, I'm trying to send text from a JavaScript to a dynamic text box in Flash. I spent all day on Friday wondering why I couldn't get it to work despite following web guides to the letter. Finally I discovered that I'm not actually doing anything wrong and everything works perfectly - as long as it's online. It won't work at all locally or from the network.

    The problem is that this is for learning material which will be deployed both online and on CD, so it won't always be running from a webserver. Has anybody got any ideas a) why this is happening, and b) what I can do about it?

    Thanks in advance for any advice or ideas!

    Marc

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Im not versed in JS very well..so not sure of its limitations being on the web or local.

    but will the javaScript even work if NOT online?

    can you have the javaScript add a variable into the 'embed' code of the HTML page..and have FLASH grab if from there off-line?

    document.write to write the flash movie object/embed code with another PARAMETER in there of the text you want to populate the textField with.

    Flash can grab & use this "flashVar" when the movie loads. maybe javaScript can write it there for you? and refresh the page. I dont think javaScript can write to a textFile can it?

  3. #3
    Junior Member
    Join Date
    Jun 2006
    Posts
    12

    Solution - HOORAH! \o/

    Thanks for your reply - it's nice to know that there are people out there to help.

    As it happens I stumbled upon the solution late in the day today. Basically, sending variables through the <param> method is fine. The problem was that I was writing a simulated nuclear experiment, which requires continuous updating of the dynamic text field, so it had to be done using a different method. I had followed all of the instructions which I could find elsewhere but for some reason it would only work online. I still don't know why that is, but in the dynamic text field properties, you need to select 'use system fonts' or it just won't work locally. Also, when exporting the movie I needed to select 'access network files only' for some reason.

    Anyway, I'm not sure if this information will be of any use to you, but it may help somebody avoid a day of screensmahsing anger and frustration

    I'm not that well up in JS either - I only started looking at it on Friday, but having programmed in quite a few other languages in the past I was surprised how easy it is to pick up.

    Anyway, thanks again for your reply - keep up the good work

    Marc

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    maybe there is a better way, than using javaScript?

    how about a local 'cookie' (sharedObject).

  5. #5
    AFX == P. Forsberg
    Join Date
    Nov 2001
    Posts
    439

    JS v. SharedObject

    Both Javascript and the SharedObject will work locally and online. If your files are working in one place and not in the other, make sure all your pathnames are correct.

    Here's a sample of how to get variables passed from JS to your Flash file via the embed tag:

    <script>
    //strips/ splits all vars from the url
    function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
    return pair[1];
    }
    }
    }
    </script>

    This goes into the head tag of your HTML page. And this bit is the embed tag:

    <script>
    //create var for swf name here in case future GET vars are needed
    var movieName = "quizTemplate.swf?id="+getQueryVariable("id");
    //writes out the object tag using the dynamic var from above
    document.write('<object classid=\"clsid27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"998\" height=\"593\"><param name=\"movie\" value=\"'+movieName+'\"><param name=\"quality\" value=\"high\"><embed src=\"'+movieName+'\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"998\" height=\"593\" ></embed></object>')
    </script>

    I can post the sharedObject info as well if you'd rather.

    Good luck,
    1M.

  6. #6
    Junior Member
    Join Date
    Jun 2006
    Posts
    12

    Javascript - Flash

    The reason I am using JavaScript is because this learning object will be deployed in alsorts of ways all over the world, and anybody with access to a JavaScript enabled browser will be able to make use of it.

    All of the maths and modelling is done in the JS, and basically all the Flash does is make a convenient graphical interface representing the lab equipment and their displays.

    Anyway, I sh1t you not, it worked perfectly online and not at all offline. I have no idea why, and there is nothing wrong with the pathnames. But if you select 'access network files only' when exporting and use 'system fonts' in the dynamic text box then it works perfectly in both locations without any adjustment to the code.

    Anyway, maybe this will be of some use.

    For reference I use the JS :

    experiment.SetVariable("time", "0069");

    This sets the variable "time" in the movie "experiment" to "0069"

    Dead simple once you figure out the weird issues.

    Thanks for all of your help guys....

    Marc

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    have you tried embeding the font? I use FLASH 8 currently, and I have had weird problems with dynamic textFields as well (had to select bitmap or embed or some combination)

  8. #8
    Junior Member
    Join Date
    Jun 2006
    Posts
    12

    Embedding the font.....

    Actually, as it happens that's the next thing on my list tomorrow. The whole simulation is working perfectly now, but embedding the font is a necessity for it to look right as it is a digital style one (for display on the simulated instruments) which is obviously non-standard. I've never really needed to embed a font in a Flash movie before so I'm not sure what it involves, but I'm presuming it's not that complicated....

    It's so bizarre though that the whole issue is caused by font related problems when I think of all the other more complex things which it could have been!

    I'll let you know how I go on....

    Cheers

    Marc

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