Getting FlashVars from class based AS3 with swfObject

Hi, I'm tryng to get a Flashvar as a string from swfObject using a document class but it is tracing a null - can anybody tell me what I'm doing wrong?

code is below

Thanks a lot, Paul
<body>
<div id="flashLoad"></div>
	<script type="text/javascript">
		// <![CDATA[
		var soFlash = new SWFObject("testClass.swf", "myDate", "184", "145", "9", "#FFFFFF");
		soFlash.addVariable("uniqueDate", "2010,4,30,00,00");
		soFlash.write("flashLoad");		
		// ]]>
	</script>

</body>




AS3:

package {

	import flash.display.MovieClip;

	public class testClass extends MovieClip {

		public var getDate:String;

		public function testClass() {
			getDate=this.root.loaderInfo.parameters.uniqueDate;
			trace(getDate);
		}
	}
}

Open in new window

LVL 2
SideasAsked:
Who is Participating?
 
IqAndreasCommented:
Are you using SWF Object version 2?

There is a free AIR app which generates the HTML wrapper for you on the SWF Object Google Code page:
http://code.google.com/p/swfobject/

Here is a nice video which describes how to use the AIR app as well as a general introduction to using SWF Object 2:
http://www.gotoandlearn.com/play?id=77


As for your actual code, try placing the script tag inside of head instead of body and see if it makes a difference. I have attached the new code with some additional changes.

If it still doesn't work, just reply back.

Good luck with your programming,
Andreas
<head>
	<script type="text/javascript">
		
		var flashVars = {}
		flashVars.uniqueDate = "2010,4,30,00,00";
		
		swfobject.embedSWF("testClass.swf", "flashLoad", "184", "145", "10.0.0", "", flashVars);
	
	</script>
</head>
<body>
    <div id="flashLoad">
        If you are seeing this message, you don't have Flash installed.
        Too bad...
    </div>
</body>

Open in new window

0
 
SideasAuthor Commented:
Thanks IqAndreas   swfObject 2 looks good.

I had to cast it as a string too:

var uniqueDate: String = LoaderInfo(this.root.loaderInfo).parameters.uniqueDate;
                  dateText.text = uniqueDate;

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.