问题
There are a number of parameters that can be added to object
and embed
tags to embed flash videos. Most are listed here. Some of them can be accessed/changed programmatically via ActionScript (e.g. <param name="scale">
can be accessed via stage.scaleMode
).
Can the value for the loop
parameter be accessed/changed?
Edit to add: I know about flashvars, that's not what I'm asking.
回答1:
The general net consensus is that no, you can not access parameters other than flashvars/movie from inside Flash.
However, you can access the parameters, in some browsers at least, from JavaScript - and of course you can interface between Flash and JavaScript using an external.
Perhaps a javascript routine along the lines of:
function getParam(paramName) {
return $('#flashid param[name=' + paramName + ']').val();
}
Along with a method in Flash:
import flash.external.ExternalInterface;
function getParam(paramName:String):String {
return String(ExternalInterface.call("getParam", paramName));
}
Obviously ensuring script access is enabled on the SWF and the object/embed.
回答2:
"Can the value for the loop
parameter be accessed/changed (via ActionScript)?"
Short answer: Don't bother.
Long answer:
@Orbling's answer relies on checking via JavaScript, which could theoretically be in an inconsistent state if the parameter was added or removed from when the embedded flash video was added.
I thought up an indirect way to check if the play or loop parameters were set. The parameters can only be detected if there are two or more frames in the root video.
First Frame
if (temp.loadParams.playParam)
{
temp.loadParams.loopParam = true;
//uses external interface to log to the console (essentially the same as trace)
temp.say('temp: looped');
stop();
}
Second Frame
if (!temp.loadParams.playParam)
{
temp.loadParams.playParam = true;
temp.say('temp: played');
}
temp
is the document class name, and loadParams is just a static object to store the param states. If the play
param is true, the video will go to frame 2, which sets the playParam
value. If the loop
param is true, the video will then go back to frame 1, which sets the loopParam
value.
If play
is false, loop
could still be detected using some fancy footwork with the Event.ENTER_FRAME
but at this point, it's ridiculous to continue checking values for a parameter that can simply be overridden by play();
or stop();
in the first or last frame.
来源:https://stackoverflow.com/questions/4270555/is-there-a-way-to-check-the-value-of-the-loop-parameter-from-actionscript