static | Web page
In the forum often see a novice asked "I want to let Flash get the parameter ID number in the URL, what to do?" How does the Flash Player of a certain video website play different ID videos? ”... Such questions see too much, each time there are a pile of replies, opinions, there will inevitably be misleading nature of the reply. Today's special combination of my usual work in the experience of this kind of problem to do a small sum.
I mean the static transfer value is different from the service-side communication for value delivery, such as loadvars,xml,remoting and so on, the latter is not in the scope of this article, when you want to let Flash get the parameters in the URL, why don't you think of a different angle? In fact, we can let the server dynamically generate SWF of the plug-in code, the initiative will we need the parameters of "static" passed to the Flash,flash direct use on it, do not need to take their own, and in what form passed to the flash, which I refer to the static value. I know there are three kinds of static value-passing methods between HTML and flash:
Use parameter passes after the SWF address? ”
Flashvars Delivery
JS Control
Here's how the three-way delivery works:
One, after the SWF address using the parameter pass character? ”
We know that we use the parameter-passing character in the ULR address? "You can pass parameters in get, such as Http://www.v-sky.com?uid=12&uname=vsky, where parameter passes are used?" , while using the connector "&" as a variable-delimited identity, passing two parameters in this canonical format: uid=12 and Uname=vsky, then the server can get the two values using the Getting method.
In Flash we can also pass parameters in a similar way, and the most common way to insert a SWF file in an HTML page is to use the OBJECT tag and the embed tag combination, which is also recommended by Adobe:
<object classid= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase= "http://fpdownload.macromedia.com/pub/ "Width=" height= "Shockwave/cabs/flash/swflash.cab" id= "flashvars" align= "Middle" >
<param name= "allowscriptaccess" value= "Samedomain"/>
<param name= "movie" value= "Http://www.webjx.com/htmldata/2007-06-05/demo.swf?uid=12&uname=vsky"/>
<param name= "Quality" value= "High"/><param name= "bgcolor" value= "#ffffff"/>
<embed src= "Http://www.webjx.com/htmldata/2007-06-05/demo.swf?uid=12&uname=vsky" quality= "High" bgcolor= "# FFFFFF "width=" height= "name=" flashvars "align=" Middle "allowscriptaccess=" Samedomain "type=" application/ X-shockwave-flash "pluginspage=" Http://www.macromedia.com/go/getflashplayer "/>
</object>
Where the bold part corresponds to the SWF file's address, then we can pass the parameter by using a method similar to the Get method in the URL, for example, the above code has written two variables to the SWF file when the page is completely loaded: uid=12 and Uname= Vsky.
Second, Flashvars transmission
You can refer to the Flash Help document to see the official definition of flashvars. In the HTML syntax, this is a property that is overlooked by many novices, and also, for example, the above argument, which uses flashvars to pass variables:
<object classid= clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 "codebase=" http:// Fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab "width=" height= "id=" Flashvars "align=" Middle ""
<param name= "allowscriptaccess" value= "Samedomain"/>
<param name= "movie" value= "http://" www.webjx.com/htmldata/2007-06-05/demo.swf "/>
<param name=" flashvars "value=" Uid=12&uname=vsky "/
<param name= "quality" value= "High"/><param name= "bgcolor" value= "#ffffff"/>
<embed src= " http://www.webjx.com/htmldata/2007-06-05/demo.swf "flashvars=" Uid=12&uname=vsky "quality=" High "bgcolor=" # FFFFFF "width=" height= "name=" flashvars "align=" Middle "allowscriptaccess=" Samedomain "type=" application/ X-shockwave-flash "pluginspage=" Http://www.macromedia.com/go/getflashplayer "/>
</object>
Same as the way, it is also directly to Flash to add these two variables. But I personally recommend this approach, combined with the use of swfobject, using Flashvars to pass variables has many advantages, such as clear code, easy to manage, browse its compatibility, meet the standards. Their combination is used in the article "constructing flexible interfaces for flash programs" I have already introduced (PS: Then I will provide a complex, persuasive practical application to illustrate the use of this flexible interface).
Third, JS control
For the resources in the client page, JS control by the DOM structure they can be said to be arbitrary, flash is no exception, the following is the Flash Player's JavaScript method list:
Play () —————————————-animation
Stopplay () ———————————— stop animation
IsPlaying () ——————————— – whether the animation is playing
Gotoframe (frame_number) —————-jump to a frame
Totalframes () ——————————-get the total number of frames for the animation
Currentframe () —————————— return the number of frames in the current animation-1
Rewind () ————————————-causes the animation to return to the first frame
Setzoomrect (Left,top,right,buttom) ——-enlarge the specified range
Zoom (percent) —————————— change animation size
Pan (x_position,y_position,unit) ———— to translate the animation in the x,y direction
percentloaded () —————————-returns the percentage of animation being loaded
Loadmovie (Level_number,path) ——— – load animation
Tgotoframe (movie_clip,frame_number)-Movie_clip jumps to the specified number of frames
Tgotolabel (movie_clip,label_name)--movie_clip jumps to the specified label
Tcurrentframe (movie_clip) ————— postback Movie_clip Current frame-1
Tcurrentlabel (Movie_clip) ————— – Postback movie_clip current label
Tplay (Movie_clip) ————————— play Movie_clip
Tstopplay (movie_clip) ———————-stop movie_clip Playback
GetVariable (variable_name) ————— – Get variables
SetVariable (variable_name,value) ——— – variable assignment
Tcallframe (movie_clip,frame_number)-call specifies the action on the frame
Tcalllabel (Movie_clip,label) —————-call specifies the action on the label
Tgetproperty (Movie_clip,property)--– Gets the specified properties of the Movie_clip
Tsetproperty (Movie_clip,property,number) ———-set the specified properties of Movie_clip
Here we only need to use the bold identification of the SetVariable method, JS by calling this method can directly change the value of the SWF variable. First we need to define the ID of the inserted SWF, for example, the ID is Vskydemo, then we can use the following JS statement to complete the SWF internal variable settings: window.document.VskyDemo.SetVariable ("UID", 12);
It's simple, that's it. Unless you are involved in HTML in addition to the SWF element to interact with it, otherwise I generally do not use JS to control the SWF variables, because I always feel strange, hehe, personal habits. A lot of practice, do not think these small things inconspicuous, small things more, poly knot together is a big application. All roads lead to Beijing, choose your favorite, you think the convenient way on it, I do not find these three ways there are functional deficiencies.
Welcome to join the discussion, such as the courtesy of the reprint, please specify the source: http://www.v-sky.com/blog/index.php/archives/179