Flex Tour--html to flex reference __html

Source: Internet
Author: User

Recently, there is a need to play an introductory video in the website, so I did a demo with Flex to play video. Video playback of the code is previously found on the Internet, but from the HTML page to get the video address when the parameter transfer problem wasted a lot of time, is summarized as follows:

Receiving parameters in Flex is simple, by FlexGlobals.topLevelApplication.parameters or directly using parameters, the parameters is described in the document as follows:

spark.components.Application.parameters (): Object Read-only contains Object that represents the name-value pair of the parameter supplied to this application.

You can use the for-in loop to extract all the names and values in Parameters Object.

The parameter has two sources: the query string in the URL of the application and the value of the Flashvars HTML parameter (for the primary application only).




Receive parameter code:

			Private Function init (): void
			{
				if (parameters!= null) {
					var source:string = Parameters.source as string;
  
   var param2:string = parameters.test as String;
				}
			}
  

The parameters parameter has two source URLs and Flashvars, which are described separately:

When you create a new Flex application, a new HTML page is created at the same time, and flex applications are embedded in HTML. This includes both JavaScript and <noscript> tags and executes the code in <noscript> only if the browser does not support JavaScript.

1. Passing Parameters via URL

This way, like the HTML URL argument, the SWF?PARAM1=PARAM1&PARAM2=PARAM2 code is as follows:

swfobject.embedSWF (
                "videoplayer.swf?source=http://material.157you.com/material/767/dcf_enc.flv&param2 =test "," Flashcontent "," "," "," ", 
                swfversionstr, Xiswfurlstr, flashvars, params 
                , attributes);
<noscript>
	<object classid= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width= "height=" "id=" Videoplayer ">
      <param name=" movie "Value=" videoplayer.swf?source=http://material.157you.com/material/ 767/dcf_enc.flv "/> ...
      <!--[if! ie]>-->
      <object type= "Application/x-shockwave-flash" Data= "videoplayer.swf?source=http://" Material.157you.com/material/767/dcf_enc.flv&param2=test "width=" "height=" >
      .... <!--<! [endif]--> ...
	</object>
<noscript>
2. Passing parameters through Flashvars

 var flashvars = {};
            Flashvars.source = "http://material.157you.com/material/767/dcf_enc.flv";
            
            FLASHVARS.PARAM2 = "Test"; swfobject.embedSWF ("videoplayer.swf", "Flashcontent", "" "," "," SwF Versionstr, Xiswfurlstr, flashvars, params, attributes); 
<noscript>
	<object classid= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width= "height=" "id=" Videoplayer ">
		<param name=" movie "value=" videoplayer.swf "/>" <param name= "Flashvars" value= "
		Source=http://material.157you.com/material/767/dcf_enc.flv&param2=test "/> ...
		<!--[if! ie]>-->
		<object type= "Application/x-shockwave-flash" Data= "videoplayer.swf" width= "500" height= " >
		    <param name= "flashvars" value= "source=http://material.157you.com/material/767/dcf_enc.flv&param2 =test "/> ...
		<!--<! [endif]--> ...
	</object>
<noscript>
Note:When both URL and flashvars arguments are used, the value of the Flashvars overrides the value of the URL if the parameter name is the same


The above is achieved by the way that flex provides specific pass parameters. There is also a way to implement parameter transfer, we know in the flex can call JS method, so you can write a method in JS, the return value is to pass the parameters, so that in flex can be obtained, This is a curve of the way to save the nation.

JS method, return parameter params:

			function Flexparams () {
				var params = {param2: ' Test '};
				Params.source = "http://material.157you.com/material/767/dcf_enc.flv";

				return params;
			}
In Flex, call the JS method and get the parameters:

			Private Function init (): void
			{
				var params:object = Externalinterface.call ("Flexparams");
				
				if (params!= null) {
					var source:string = Params.source as String;
					var param2:string = params.param2 as String;
				}
			}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.