;

PDA

Click to See Complete Forum and Search --> : Easy for you: How to get parameter


gsub
11-05-2008, 07:23 AM
Hi guys

Guess this is easy for you gurus :cap:

I call my RadarTest.swf from within a html page:



<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? :confused:

Thank you for helping a newbie :-)

gsub

neznein9
11-05-2008, 09:35 AM
loaderInfo.parameters.testparam

5TonsOfFlax
11-05-2008, 09:57 AM
Does that really work? I've always used flashvars for that.

neznein9
11-05-2008, 11:53 AM
Scratch that - Flax is right, the html should be modified to read:

<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>

gsub
11-06-2008, 02:54 AM
Thanks guys for your help, hmm have to admit I'm a bit confused now...

This is the call in my HTML now:


<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:




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... :confused:

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")? :scared:

Thanks again
GSub

5TonsOfFlax
11-06-2008, 09:50 AM
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=South|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.

gsub
11-06-2008, 12:11 PM
Thanks Flax for your time :)

Yes you're right! Never do things manually, when Dreamweaver can do it right for you ;-)

With a little help from this tutorial
http://www.flepstudio.org/forum/tutorials/657-passing-variables-html-flash-cs3.html

I was able to make it run. Here is the coding:





package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.display.LoaderInfo;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;

public class Main extends Sprite {
private var id:String;
private var _MemText:TextField;

public function Main() {
configureMemText();
getHTMLvars();
}
private function getHTMLvars():void {
var value:String;
var obj:Object=LoaderInfo(root.loaderInfo).parameters;
for (value in obj) {
id=String(obj[value]);
_MemText.text=id;
}
}
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);
}
}
}



Thanks for your suggestion with the arrays. Hmm, I'm sure that works, but it would be nice, if you could just pass an array to AS... Would that be possible with 'ExternalInterface'? Havent heard about this one... Hmm, do you have any resources/link where I could find out how to use it for my prob?

Thanks for the hint with the coordinates. My project is a custom radar chart. I've got the major shape and drawings but a bit stuck with my math skills :scared: :rolleyes: :-) But first things first ;-)

Thanks again
GSub

5TonsOfFlax
11-06-2008, 12:20 PM
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:

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);
}

gsub
11-06-2008, 12:52 PM
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

5TonsOfFlax
11-06-2008, 12:59 PM
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/ActionScriptLangRefV3/flash/external/ExternalInterface.html

gsub
11-06-2008, 01:06 PM
Thanks again Flax and take care :-)