A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Easy for you: How to get parameter

Hybrid View

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    6

    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

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    loaderInfo.parameters.testparam

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Does that really work? I've always used flashvars for that.

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    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

  5. #5
    Junior Member
    Join Date
    Nov 2008
    Posts
    6
    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

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  7. #7
    Junior Member
    Join Date
    Nov 2008
    Posts
    6
    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/tuto...flash-cs3.html

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

    Code:
    
    
    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 :-) But first things first ;-)

    Thanks again
    GSub

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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);
    }

  9. #9
    Junior Member
    Join Date
    Nov 2008
    Posts
    6
    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

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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

  11. #11
    Junior Member
    Join Date
    Nov 2008
    Posts
    6
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center