dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Flash Var to Dynamic Text Field

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    2

    Flash Var to Dynamic Text Field

    Let me start off like most AS3 noobies and say sorry for the following question that might seem trivial.

    I have a 3 word phrase that needs to be in my flash movie, and it needs to be localized. I'm using an external AS file for all my code. Figured I would just make a flash var and pass our string value in that way. So I made a dynamic text field, gave it an instance name of "mytextfield" which is in a MC called "detail_mc".

    Just for kicks I tested my code on the stage just on a keyframe, this was the code:

    Code:
    var myText:String;
    if (mytext == undefined) myText = "No Value Entered";
    mytextfield.text = myText;

    That worked for my test. So I took this over to my AS file and there is just no magic happening. I'm not exactly sure whats the problem but hoping its a simple fix. I've been looking for a few hours but nothing has helped

    Any help would be very much appreciated. Thank you in advance for any replies.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Describe the problem in more detail. Are you getting an error, perhaps saying that the compiler doesn't know what mytextfield is?

    Or do you mean you can't get the values from the flashvars? Flashvar behavior has changed in as3, the vars are now found in the parameters object of the loaderInfo.

  3. #3
    Senior Member
    Join Date
    May 2004
    Posts
    226
    First off, the reason your snippet appeared to work is because you have a typo:
    var myText:String;
    if (mytext == undefined) myText = "No Value Entered";
    mytextfield.text = myText;

    mytext is truly undefined in that it does not exist as an object, where as:

    var myText:String;
    if (myText == undefined) myText = "No Value Entered";
    mytextfield.text = myText;

    will throw the following warning:
    Warning: 1012: Variables of type String cannot be undefined. The value undefined will be type coerced to String before comparison.

    What you probably want to test for is null which is quite different than undefined.

  4. #4
    Junior Member
    Join Date
    May 2009
    Posts
    2
    Heres some answers to questions that might better explain my problem:

    1. Are you getting compiler or runtime errors? If so, what are they?

    No Errors.

    2. If you're not getting errors, are you creating the TextField instance in code? If yes, has it (or its parent MovieClip) been added to the stage?

    I have created the MC on the stage with the TextField nested inside of it. The MC name is detail_mc (no instance name) and the dynamic text field has an instance name of myTextField.

    3. What is triggering your updates to the textfield's text property (how do you assign the value you want)? Do you have change listeners on some input textfields or is it in an enterFrame listener for example?

    I want to update the text field with a flash var. So when I embed the SWF I can pass my translated string.
    Last edited by wid; 05-18-2009 at 12:59 PM.

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yeah, that's definitely AS2. But, it's typed and fairly sensibly written. The conversion to AS3 shouldn't be too hard. The main parts are that loadMovie needs to actually be a Loader, the onWhatever property functions need to use addEventListener instead, and getURL needs to be navigateToURL.

    I see textfield declared (as a String), but I don't see it used anywhere. For that matter, I don't see any flashvar stuff either. As I said above, flashvars are handled differently in AS3. In AS2, they simply overwrote whatever root level variable was already there with that name. In AS3, they go into an Object called parameters which is on the LoaderInfo object associated with the root. To get the value specified by the flashvar myTextValue, you'd do this:

    Code:
    var myTextValue:String = root.loaderInfo.parameters.myTextValue;

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