Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

FlashVars and Actionscript 3.0

Posted on 2009-04-02
7
642 Views
Last Modified: 2013-11-12
I have the below actionscript, what I am trying to do is dynamically pass the name of the xml file using flashvars. For some reason I am getting the  Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///C:/Documents%20and%20Settings/CRobinson/Desktop/Thermometer/xml/undefined.xml
      at thermometer_fla::thermometer_1/thermometer_fla::frame1()

See the attached txt file that is embedding the variable. Also see the actionscript to see how I am attempting to access this FlashVar called myVar. Any help here would be greatly appreciated. Thanks
stop();
import caurina.transitions.Tweener;//import tween class
stage.scaleMode = StageScaleMode.NO_SCALE;//define how stage scales
stage.align = StageAlign.TOP_LEFT;
//get all the vars from the xml file
var xmlString:URLRequest = new URLRequest("xml/" + root.loaderInfo.parameters.myVar + ".xml");
var xmlLoader:URLLoader = new URLLoader(xmlString);
xmlLoader.addEventListener("complete", init);
function init(event:Event):void {
	var xDoc:XMLDocument = new XMLDocument();
	xDoc.ignoreWhite = true;
	var thermXML:XML = XML(xmlLoader.data);
	xDoc.parseXML(thermXML.toXMLString());
	//get vars
	var goalTxt:String = xDoc.firstChild.childNodes[0].firstChild.nodeValue;//goal text
	populateGoal(goalTxt);//populate the goal text
	var goalNum:Number = xDoc.firstChild.childNodes[0].attributes.goalNum;//goal number
	var currentNum:Number = xDoc.firstChild.childNodes[1].attributes.currentNum;//current number
	makeCurrent(goalNum, currentNum);
	//marks
	var marksArray:Array = new Array;
	var marksLength:Number = xDoc.firstChild.childNodes[2].childNodes.length;
	for(var i:Number = 0;i<marksLength;i++){
		var markNum:Number = xDoc.firstChild.childNodes[2].childNodes[i].attributes.markNum;
		var markNumString:String = addCommas(markNum);
		addMark(markNumString, markNum, goalNum, currentNum);
	}
}
 
//populate goal text
function populateGoal(getGoalTxt:String):void {
	goal_txt.htmlText = getGoalTxt;
}
//make progress bar
var goalHeight:Number = 170;
function makeCurrent(goalNum:Number, currentNum:Number) {
	var percDone:Number = currentNum/goalNum;
	var progressY:Number = goalHeight - (goalHeight* percDone);//determine what y should be
	Tweener.addTween(progress_mc, {y:progressY, time:3, onUpdate:reportPosition, onUpdateParams:[progressY, goalNum, currentNum]});//tween progress
	Tweener.addTween(mask_mc, {y:progressY, time:3});//tween mask
}
//position during tween
function reportPosition(progressY:Number, goalNum:Number, currentNum:Number):void {
	var currentProgressY:Number = progress_mc.y;
	var percentDone:Number = 1 - (currentProgressY/goalHeight);
	var currentValue:Number = Math.floor(percentDone* goalNum);
	if (currentValue > currentNum) {
		currentValue = currentNum;//if the current value is more than what is should be...
	}
	progress_mc.progress_txt.htmlText = "$" + addCommas(currentValue);
}
//format number with commas
function addCommas(getDollarAmount:Number):String {
	var amountArray:Array = String(getDollarAmount).split();//split the string into an array
	var dollarArray:Array = new Array();
	var startNum:Number;
	var endNum:Number = amountArray[0].length;//length of the number
	while (endNum > 0) {
		startNum = Math.max(endNum - 3, 0);
		dollarArray.unshift(amountArray[0].slice(startNum, endNum));
		endNum = startNum;
	}
	amountArray[0] = dollarArray.join(",");//join all the nodes of the dollar array together
	return (amountArray[0]);//return the number with the ,s
}
//add marks
function addMark(markString:String, markNum:Number, goalNum:Number, currentNum:Number){
	var mark_mc:mark = new mark();
	mark_mc.x = 65;
	var percDone:Number = markNum/goalNum;
	var markY:Number = goalHeight - (goalHeight* percDone);//determine what y should be
	mark_mc.y = markY;
	mark_mc.mark_txt.text = "$" + markString;
	this.addChild(mark_mc); 
}

Open in new window

thermometer.txt
0
Comment
Question by:E-Risk
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:asaivan
ID: 24054391
I'm not seeing this var listed in the Javascript part of your embed code.  It is in the <noscript> block, but not in the <script> block.
There should be 'myvar', '10868'
0
 
LVL 2

Author Comment

by:E-Risk
ID: 24054544
I added the code below same error.
<script language="javascript">
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '590',
			'height', '300',
			'src', 'thermometer',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'thermometer',
			'bgcolor', '#ffffff',
			'name', 'thermometer',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', 'thermometer',
			'myVar', '10868',
			'salign', ''
			); //end AC code
	}
</script>
<noscript>
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="590" height="300" id="thermometer" align="middle">
	<param name="allowScriptAccess" value="sameDomain" />
	<param name="allowFullScreen" value="false" />
	<param name="movie" value="thermometer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="thermometer.swf" quality="high" bgcolor="#ffffff" width="590" height="300" name="thermometer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" myVar="10868"/>
	</object>
</noscript>

Open in new window

0
 
LVL 9

Expert Comment

by:asaivan
ID: 24054586
My fault, you actually don't need that, just add the query sting to the swf name.

my.swf?myvariable=variablevalue
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 2

Author Comment

by:E-Risk
ID: 24054735
This is what I get:Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///C:/Documents%20and%20Settings/CRobinson/Desktop/Thermometer/xml/undefined.xml
      at thermometer_fla::thermometer_1/thermometer_fla::frame1()

Here is what I added:
<param name="movie" value="thermometer.swf?myVar=10868" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="thermometer.swf" quality="high" bgcolor="#ffffff" width="590" height="300" name="thermometer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" myVar="10868"/>

Here is the action script I am using to try and refernce the variable:
var xmlString:URLRequest = new URLRequest("xml/" + this.loaderInfo.parameters.myVar + ".xml");
0
 
LVL 9

Accepted Solution

by:
asaivan earned 500 total points
ID: 24054811
remove myvar references from your embed code and try this instead.  add to script block (and no script using appropriate notation).

'FlashVars','myVar=10868'
0
 
LVL 2

Author Comment

by:E-Risk
ID: 24054860
As this ?
<script language="javascript">
      if (AC_FL_RunContent == 0) {
            alert("This page requires AC_RunActiveContent.js.");
      } else {
            AC_FL_RunContent(
                  'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
                  'width', '590',
                  'height', '300',
                  'src', 'thermometer',
                  'quality', 'high',
                  'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                  'align', 'middle',
                  'play', 'true',
                  'loop', 'true',
                  'scale', 'showall',
                  'wmode', 'window',
                  'devicefont', 'false',
                  'id', 'thermometer',
                  'bgcolor', '#ffffff',
                  'name', 'thermometer',
                  'menu', 'true',
                  'allowFullScreen', 'false',
                  'allowScriptAccess','sameDomain',
                  'movie', 'thermometer',
                  'FlashVars','myVal=10868'
                  'salign', ''
                  ); //end AC code
      }
</script>

<noscript>
      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="590" height="300" id="thermometer" align="middle">
      <param name="allowScriptAccess" value="sameDomain" />
      <param name="allowFullScreen" value="false" />
      <param name="movie" value="thermometer.swf?myVar=10868" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />      <embed src="thermometer.swf" quality="high" bgcolor="#ffffff" width="590" height="300" name="thermometer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>
      </object>
</noscript>
0
 
LVL 2

Author Comment

by:E-Risk
ID: 24054872
Awesome! Works like a charm.
I was sooo close....Thanks for the help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Writing .htaccess to redirect only the index page 3 93
monthly fee and support for nutrionist 3 143
you tube .com 2 206
javascript to html map 8 94
In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question