Flash for the masses – AS, JSFL, XUL, etc.

2009/01/08

Current URL of the SWF file – super easy, but super annoying.

Filed under: AS3.0, Adobe, Flash — delfeld @ 8:57 pm
Tags: , , , , , , ,

It’s just hidden, that’s all. It would be better to go back to the days of root.url, but that’s too easy.

Anyway, the super simple code is:

		this.root.loaderInfo.url

And just to make your life so much easier, here are a couple of methods to display this onscreen:

		protected function slapOnText():void
		{
			var tf:TextField = new TextField();
			tf.addEventListener(Event.ADDED_TO_STAGE, addTFHnd);
			addChildAt(tf,this.numChildren-1);
		}

		protected function addTFHnd(e:Event):void
		{
			e.target.removeEventListener(e.type, addTFHnd);

			var tf:TextField = TextField(e.target);

			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.multiline = true;
			//tf.wordWrap = true;
			tf.textColor = 0xFFFFFF;
			tf.scaleX = scaleY = 1.5;

			// currently, this adds the URL info to the view, but it can be anything.
			tf.text = "URL: " + this.root.loaderInfo.url;
		}

Blog at WordPress.com.