1

I am trying to send username from HTML to ActionScript 3. And I referred this tutorial

HTML Code:

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>      
    <object width="100" height="100">
        <param name="movie" VALUE="test.swf">
        <param name="FlashVars" VALUE="userName=permadi">
        <embed src="test.swf" FlashVars="userName=permadi" width="1024" height="768">
        </embed>
    </object>
</body>
</html>

Actionscript3 Code:

 function loaderComplete(myEvent:Event)
{
  var flashVars=this.loaderInfo.parameters;
  userNameTextField.text=flashVars.userName;
}

var flashVars=new Object();
flashVars.loaderCOmplete:function=loaderComplete;
this.loaderInfo.addEventListener(Event.COMPLETE, flashVars.loaderComplete);

But userNameTextField in swf file does not displays userName value.

1 Answer 1

3

To get your flashvars, you can do like this :

this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(myEvent:Event)
{
    var flashVars =  this.loaderInfo.parameters;
    // verify if your flash var is set
    if(flashVars.userName){
        userNameTextField.text = flashVars.userName;
    }
}

Or simply like this :

// verify if your flash var is set and set a default value if not, if you want of course
userNameTextField.text = this.loaderInfo.parameters.userName ? this.loaderInfo.parameters.userName : 'default value';

And don't forget to embed your font as flash said : "Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.", you can see here how to embed fonts for a dynamic text field.

Sign up to request clarification or add additional context in comments.

2 Comments

Why not userNameTextField.text = this.loaderInfo.parameters.userName || 'default value'; ?
@Cherniv Yes, It's possible too, but I tried to do easy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.