Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Page 1 of 5
1 2 3 ... LastLast
Results 1 to 10 of 46

Thread: Passing variables from HTML to Flash CS3

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,454
    Rep Power
    8

    Passing variables from HTML to Flash CS3

    amazing Flash templates
    We have seen how to pass some values from Flash CS3 to PHP that allows us to maintain in communication our Flash applications with the server.
    We often need to assign to a SWF a value in entry using the HTML of the page in which the SWF itself is inserted.

    With Flash 8 all it took, was defining a variable on the timeline and assigning it the value through the HTML.
    With Flash CS3, things have a bit changed and we need to work with the LoaderInfo class. So let us follow the next example...

    In this example, I use Adobe Dreamweaver to insert a SWF in a HTML page and to pass a value to the SWF.

    I create a FLA and save it as "main.fla".
    I create an HTML page with Dreamwearver and save it as "main.html".
    I add "main.swf" to the HTML page "main.html".
    I select the SWF and I open the Parameters Panel as shown in the following pic:



    as we can be notice, I insert as a parameter name "flashvars" (in this way Flash knows that there is a parameter - let us see it this way), otherwise it does not work.
    In the field Value (Valore), I insert "id=321". "id" will be the name of the variable that Flash will look for and 321 is its value.

    Back to "main.fla", I assign a Document Class, an AS file saved as "Main.as", implemented the following way:
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.text.TextField;
    	import flash.display.LoaderInfo;
    	
    	public class Main extends MovieClip
    	{
    		private var id:String;
    		
    		public function Main()
    		{
    			getHTMLvars();
    		}
    		
    		private function getHTMLvars():void
    		{
    			var value:String;
    			var obj:Object=LoaderInfo(root.loaderInfo).parameters;
    			for (value in obj)
    			{
    				id=String(obj[value]);
    				try_txt.text=id;
    			}
    		}
    	}
    }
    In brief, I told Flash to retrieve the value of "id" passed by the HTML.

    Let us analyse the code.

    Properties

    a String variable with the same name (we are not obliged to do so) as the variable passed by the HTML
    private var id:String;

    Methods
    getHTMLvars();
    this methods implements the logic to retrieve the variable "id" from the HTML
    a String variable used in a "for in" cycle
    var value:String;
    an Object variable to which I assign the property "parameters" of LoaderInfo from the "main.fla""s root
    var obj:Object=LoaderInfo(root.loaderInfo).parameters;
    with a "for in" cycle, I check if there is a String in the object "obj"
    for (value in obj)
    {
    I assign to the property "id" a value as a "String" type equal to a fake property retrieved from "obj" (we could also see it as "obj.value" but Flash CS3 would not accept it)
    id=String(obj[value]);
    I assign the value of the property "id" as a text of a text field so to be sure that Flash sees that variable passed by the HTML
    try_txt.text=id;
    }

    Clearly, I added the text field only to demonstrate this example. Once, the value of the variable "id" is retrieved from the HTML and is assigned to the property "id" of "Main.as",
    we can use that value as wanted all through our Flash application.

    Stay tuned!

  2. #2
    Junior Member Settled In mxmania is on a distinguished road
    Join Date
    Dec 2007
    Posts
    6
    Rep Power
    0

    Re: Passing variables from HTML to Flash CS3

    Hi,
    Thx for the first such tutorial for flash CS3.
    I am trying to retrieve variable value "id" to obtain the name of the flv file to be run by flv player component in Flash CS3

    var id:String;
    //id = "images/admin/flv/m.flv";
    // loads source property
    myFLVPlybk.source = id;
    // loads source parameter of load() method
    myFLVPlybk.load(id);
    // loads source parameter of play() method
    myFLVPlybk.play(id);

    This works fine when use id = "http://www.flepstudio.org/forum/images/admin/flv/m.flv";
    but if commented no values are obtained.
    AS file is inluded in the same folder but has no effect. Am I missing something?

    on ASP page, i am passing the url value:


    " name="Flashvars">


    I would be grateful if you could give me some hint. This would also help loads of other people who are trying to run FLV files dynamically.

    Regards
    Khna

  3. #3
    Junior Member Settled In mxmania is on a distinguished road
    Join Date
    Dec 2007
    Posts
    6
    Rep Power
    0

    Re: Passing variables from HTML to Flash CS3

    Just small correction:
    This works fine when use id = images/admin/flv/m.flv;
    on ASP page, i am passing the url value:

    param name="Flashvars" value="id=<%= user %>"
    " name="Flashvars">

    Thx and Happy New years

  4. #4
    Junior Member Settled In mxmania is on a distinguished road
    Join Date
    Dec 2007
    Posts
    6
    Rep Power
    0

    Re: Passing variables from HTML to Flash CS3

    somehow the forum code replaces my code lol, haven't red the rules sorry.
    Value passed from my ASP page is
    param name
    name="Flashvars"
    value="id=myRetrievedValue"

  5. #5
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,454
    Rep Power
    8

    Re: Passing variables from HTML to Flash CS3

    Hi,
    what you mean with " value passed from ASp page " ?
    ASP create HTML code to embed the SWF and pass the value or ASP script must be called by Actionscript ?

  6. #6
    Junior Member Settled In cooljackD is on a distinguished road
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Re: Passing variables from HTML to Flash CS3

    wot if yu have two values to pass to flash cs3

    like :




    how do retrieve it in the flash document CLASS
    with the LoaderInfo.parameters

    as you did in your example

    Thanks

    Best wishes for 2008

  7. #7
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,454
    Rep Power
    8

    Re: Passing variables from HTML to Flash CS3

    Hi cooljackD,

    with more HTML vars:

    HTML code
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>html vars to flash CS3</title>
    <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
    </head>
    
    <body>
    <script type="text/javascript">
    AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','300','height','150','src','main','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','flashvars','id=444&ir=888','movie','main' ); //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,28,0" width="300" height="150">
      <param name="movie" value="main.swf" />
      <param name="quality" value="high" />
      <param name="flashvars" value="id=444&amp;ir=888" />
      <embed src="main.swf" width="300" height="150" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" flashvars="id=444&amp;ir=888"></embed>
    </object>
    </noscript>
    </body>
    </html>
    Actionscript
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.text.TextField;
    	import flash.display.LoaderInfo;
    	
    	public class Main extends MovieClip
    	{
    		private var id:String;
    		private var my_array:Array=new Array();
    		
    		public function Main()
    		{
    			getHTMLvars();
    		}
    		
    		private function getHTMLvars():void
    		{
    			var value:String;
    			var obj:Object=LoaderInfo(root.loaderInfo).parameters;
    			for (value in obj)
    			{
    				id=String(obj[value]);
    				my_array.push(id);
    				try_txt.text=my_array.toString();
    			}
    		}
    	}
    }

  8. #8
    Junior Member Settled In cooljackD is on a distinguished road
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Re: Passing variables from HTML to Flash CS3

    Thanks for the quick answer, it really put some light on lots of things
    so as you explained the ~value~ is the object we track from the vars we get from the html page and the id is the object containing the values of the of its container but instead of reading it in a textfield throught trace is the any way to the see all the objects retrieved from flash, i used to do list varialble and if the array was set to a global variable you could actually see all the array collection retrieved and now with as3 you can see anything is the a way to do that, its for futur things of i'm still trying to get use to the new ide flash cs3

  9. #9
    Junior Member Settled In cooljackD is on a distinguished road
    Join Date
    Dec 2007
    Posts
    12
    Rep Power
    0

    Re: Passing variables from HTML to Flash CS3

    hi flep
    how would you retrieve the flashvars if you intend to use in an external swf

    since with flash cs3 you need a preloader and the your app how to you get the flash vars in the app after it is loaded by the preloader ???

  10. #10
    Junior Member Settled In rexus is on a distinguished road
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Re: Passing variables from HTML to Flash CS3

    Hi Flep, thank you for this tutorial.
    anyway, using my_array.toString(); will give a result of 444,888 on the text field.

    what if I have 2 text fields and I want to fill it with my_array[0] and my_array[1]?
    how to do that?
    I've been trying like:

    try_txt1.text = my_array[0];
    try_txt2.text = my_array[1];

    where try_txt1 and try_txt2 are a dynamic textfield I created on the screen.

    how do I do that?

+ Reply to Thread
Page 1 of 5
1 2 3 ... LastLast

Similar Threads

  1. Passing variable from parent to child swf using FlashVars
    By matius in forum Actionscript 3.0 newbies
    Replies: 1
    Last Post: 27-09-09, 13:09
  2. passing array button to animate
    By gwulfwud in forum advanced Actionscript 3.0
    Replies: 1
    Last Post: 02-09-08, 12:33
  3. Displaying PHP Variables in Flash
    By chosendesigns in forum PHP | mySQL | Flash CS3
    Replies: 1
    Last Post: 14-05-08, 13:49
  4. passing DisplayObject references trough XML
    By dedavai in forum advanced Actionscript 3.0
    Replies: 1
    Last Post: 21-01-08, 10:11
  5. passing DisplayObject references trough XML
    By dedavai in forum advanced Actionscript 3.0
    Replies: 0
    Last Post: 21-01-08, 09:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Optimization by vBSEO