|
-
Easy for you: How to get parameter
Hi guys
Guess this is easy for you gurus
I call my RadarTest.swf from within a html page:
Code:
<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="550" height="400" id="RadarTest" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="RadarTest.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />
<param name="testparam" value="12345">
<embed src="RadarTest.swf" width="550" height="400" align="middle" quality="high" bgcolor="#ffffff" name="RadarTest" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" testparam="12345" />
</object>
How can I retrieve the value of the parameter 'testparam' in my AS3 coding?
Thank you for helping a newbie :-)
gsub
-
loaderInfo.parameters.testparam
-
Does that really work? I've always used flashvars for that.
-
Scratch that - Flax is right, the html should be modified to read:
PHP Code:
<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="550" height="400" id="RadarTest" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="RadarTest.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name=FlashVars value="testparam=12345" />
<embed src="RadarTest.swf" width="550" height="400" align="middle" quality="high" bgcolor="#ffffff" name="RadarTest" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="testparam=12345" />
</object>
-
Thanks guys for your help, hmm have to admit I'm a bit confused now...
This is the call in my HTML now:
Code:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="550" height="400">
<param name="movie" value="text2.swf" />
<param name="quality" value="high" />
<param name=FlashVars value="testparam=12345" />
<embed src="text2.swf" width="550" height="400" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" testparam="12345"></embed>
</object>
This is my AS file. As I dont really get how to debug in the browser, I'd just display the value of the parameter as text:
Code:
package{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class TextTest2 extends Sprite {
private var _MemText:TextField;
public function TextTest2() {
configureMemText();
var pText:String = loaderInfo.parameters.testparam;
if (!pText) pText = "didnt get it!";
MemText = pText;
//MemText="Hello World and welcome to the show";
}
public function set MemText(str:String):void {
_MemText.text=str;
}
private function configureMemText():void {
_MemText=new TextField ;
_MemText.autoSize=TextFieldAutoSize.LEFT;
_MemText.background=true;
_MemText.border=false;
var format:TextFormat=new TextFormat ;
format.font="Verdana";
format.color=0xFF0000;
format.size=12;
format.underline=false;
format.bold=true;
_MemText.defaultTextFormat=format;
addChild(_MemText);
}
}
}
" loaderInfo.parameters.testparam; " doesnt seem to work though...
according to AS3 doc, it should be possible to loop over loaderInfo.parameters to read object/value pairs...
OK.. My final goal is to draw a chart and for this I have to call the chart providing members and values. What would be BestPractice for calling an swf providing (let's say) 2 arrays with members and values (Regions: "South, Nord, East, West" / Profit: "100,200,500,600")?
Thanks again
GSub
-
You need to change the parameter in the embed tag too.
As for the multiple values thing, you could do it with flashvars by passing multiple name-value pairs.
flashvars="labelx=Regions&labely=Profit&xnames=Sou th|Nord|East|West&yvalues=100|200|500|600"
You'll have to parse out the arrays using the split method, and then turn the resulting array of Strings into an array of Numbers.
You could also do it with ExternalInterface after the swf has loaded, and pass in proper javascript objects. There are pros and cons each way.
Also, it looks like you're not providing any x values, so make sure your chart does something intelligent in that case like equally spacing the data points.
-
-
Yes, you can pass arrays and objects from javascript to flash using ExternalInterface. The down-side for your project is that the swf must already be loaded in order to do so, so you'll have a bit of javascript to write as well as flash, and it would take longer to show up visually. I'd stick with flashvars on this one.
Here's some code to take a | delimited string and turn it into an array of numbers:
Code:
var someString:String = "100|300|500|400"; //pretend this is from flashvars
var someArray:Array = someString.split("|"); //array of Strings.
var someNumArray:Array = someArray.map(makeNum);
function makeNum(s:String):Number{
return Number(s);
}
-
Thanks again :-) I especially like the makeNum :-)
As I will have to draw several charts on one page and the variables have to be put together dynamically, it would also mean quite a bit of tiring js-string-concats ;-)
Still want to check out if the ExternalInterface would make it easier. Do you know of any good resources, explaining how this can be used?
Also found this one. http://code.google.com/p/swfobject/ Not sure yet if it's helpful though...
Thanks
GSub
-
I use swfobject, and I like it. It doesn't help with your problem, but it does vastly simplify getting your swf embedded on a page.
The best resource for ExternalInterface, in my opinion, is the livedocs:
http://livedocs.adobe.com/flash/9.0/...Interface.html
-
Thanks again Flax and take care :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|