Skip to main content
AdrianParr
Known Participant
September 5, 2010
Question

Flash CS5 TLFTextFields and FlashVars Problem

  • September 5, 2010
  • 2 replies
  • 3291 views

I have found that when I use a TLFTextField in Flash CS5 I no longer have access to the FlashVars passed in from HTML.

For example, when there is a TLFTextField on stage the following document class doesn't find any FlashVars ...

(In this example I am using Arthropod to view the output -http://arthropod.stopp.se)

package
{
    import flash.display.MovieClip;
    import flash.display.LoaderInfo;
    import com.carlcalderon.arthropod.Debug;

    public class TraceFlashVars extends MovieClip
    {
      
        public function TraceFlashVars():void
        {
            Debug.clear();
            // Trace out all the FlashVars
            Debug.log("-- FLASHVARS --------------------------------");
            var keyStr:String;
            var valueStr:String;
            var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
            var numOfFlashVars:int = 0;
            for (keyStr in paramObj) {
                valueStr = String(paramObj[keyStr]);
                Debug.log(keyStr + ": " + valueStr);
                numOfFlashVars++;
            }
            Debug.log("---------------------------------------------");
            if (numOfFlashVars == 0) {
                Debug.log("No FlashVars were found!");
            } else {
                Debug.log(numOfFlashVars+" FlashVars were found.");
            }
        }

    }

}

I've done some Googling and found a blog post by Steven Sacks which is related, but is more about loading child SWF and not FlashVars.

http://www.stevensacks.net/2010/05/28/flash-cs5-tlf-engine-causes-errors-with-loaded-swfs/

Please can you help me get my FlashVars working again?

Cheers,

Adrian

This topic has been closed for replies.

2 replies

AdrianParr
Known Participant
September 5, 2010

The crucial part is ...

var params:Object = loaderInfo.parameters;

if (parent != null && parent.parent != null) {

params = parent.parent.loaderInfo.parameters;

}

September 5, 2010

http://forums.adobe.com/message/2859307#2859307

AdrianParr
Known Participant
September 5, 2010

Hi Alan,

Thanks for the very speedy response!!

That worked, cheers.

Just for the record, if you are having a problem accessing your FlashVars (and you are using a TLFTextField in Flash CS5) and you are using external classes (i.e. you have a document class and not timeline code) you need to listen for the ADDED_TO_STAGE event before trying to access them.

For example ...

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.display.LoaderInfo;

    public class Main extends Sprite
    {
      
        public function Main():void
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
       
        private function init(evt:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            var params:Object = loaderInfo.parameters;
            if (parent != null && parent.parent != null) {
                params = parent.parent.loaderInfo.parameters;
            }
            // You can now loop through the params to access your FlashVars
        }
       
    }
}

I hope this gets fixed soon. It seems like a big oversight.

Regards,

Adrian