FLVPlayback/VideoPlayer: How to access VideoPlayer.load() method that accepts 5 parameters? - actionscript-3

I want to use the following load() method that accepts five parameters so that I can load a small "excerpt" from a larger video:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/video/VideoPlayer.html#load()
In particular, the startTime and duration parameters seem to be what I need, but I am getting errors that seem to indicate that I don't have the right object/version of something, even though the Adobe docs say that it should work. Here are my steps:
Start a new, blank FLA document (AS3).
Drag an FLVPlayback component to the stage and name it vPlayer.
Create a new layer and add Actionscript in frame 1:
import fl.video.*;
var innerPlayer = vPlayer.getVideoPlayer(vPlayer.activeVideoPlayerIndex);
trace(innerPlayer); // "[object VideoPlayer]" appears in Output window
innerPlayer.load(
"RTMP://..."
, 0 // totalTime
, false // isLive
, 60 // startTime
, 10 // duration
);
This should give me a ten-second clip starting from the one-minute mark, but I keep getting errors like ArgumentError: Error #1063: Argument count mismatch on fl.video::VideoPlayer/load(). Expected 1, got 5.
I've also tried casting innerPlayer to fl.video.VideoPlayer, but that doesn't work.
What am I doing wrong?
EDITS: Even though I'm on CS4/AS3 and the documentation claims to apply to CS4/AS3, the class files in my "Component Source" folder don't seem to match the documentation. I also tried this in CS6, and I got "1137: Incorrect number of arguments. Expected no more than 3."
#SunilD. - For CS4: FLVPlayback.VERSION=2.1.0.19, and I am targeting Flash Player 10 (the most recent available)+AS3. For CS6, FLVPlayback.VERSION=2.5.0.26, and I am targeting Flash Player 11.4.
In CS4 and CS6, the errors say that VideoPlayer load() only requires one argument (with two optional), and play() has three optional arguments. The output of describeType(innerPlayer) confirms:
<type name="fl.video::VideoPlayer" base="flash.media::Video" isDynamic="false" isFinal="false" isStatic="false">
...
<method name="play" declaredBy="fl.video::VideoPlayer" returnType="void">
<parameter index="1" type="String" optional="true"/>
<parameter index="2" type="Number" optional="true"/>
<parameter index="3" type="Boolean" optional="true"/>
</method>
...
<method name="load" declaredBy="fl.video::VideoPlayer" returnType="void">
<parameter index="1" type="String" optional="false"/>
<parameter index="2" type="Number" optional="true"/>
<parameter index="3" type="Boolean" optional="true"/>
</method>
...
</type>
Other notes: Flash CS6 is up to date. Manually installing the FLVPlayback 2.5 component didn't work.

Anon, I think this is an issue of poor documentation / too many different products (Flash, Flex, player, flvplayback component) with different versions.
I was able to get the .load() call to work with all 5 arguments (and verified that it did start playing at the specified start time), but only by compiling a new FLVPlayback_116.swc from the latest Flex SDK source code (Flex 4.6 with playerglobal.swc version 11.6).
See my screenshot.
Might as well see if it works for you. Here's what you'll need to do:
Remove the FLVPlayback component from your library - this defines conflicting classes with the updated version.
Download my FLVPlayback_116.swc library
Or FLVPlayback_116_air.swc if you're targeting Adobe AIR, not Flash Player / web
In Flash, open the File -> ActionScript Settings dialog, under the library path tab, click 'Browse to SWC file' and locate the FLVPlayback_116.swc file you just downloaded. My screenshot above shows this dialog and how the FLVPlayback_116.swc file is listed after being added.
In the code (see below):
You need to set: fl.video.VideoPlayer.iNCManagerClass = fl.video.NCManager;
Rather than using innerPlayer = vPlayer.getVideoPlayer you'll need to use innerPlayer = new VideoPlayer(width,height) and then addChild(innerPlayer) and innerPlayer.play()
I had to add the innerVideo.play() call to start the video playing (which I assume the GUI would handle)
Here's my code (also visible in the screenshot):
import fl.video.*;
fl.video.VideoPlayer.iNCManagerClass = fl.video.NCManager;
var innerPlayer = new VideoPlayer(640,480);
addChild(innerPlayer);
innerPlayer.load(
"http://10.0.1.3/test.flv"
, 0 // totalTime
, false // isLive
, 5 // startTime
, 5 // duration
);
innerPlayer.play();
Also, you can see that my describeType of VideoPlayer shows the proper number of arguments:
<method name="load" declaredBy="fl.video::VideoPlayer" returnType="void">
<parameter index="1" type="String" optional="false"/>
<parameter index="2" type="Number" optional="true"/>
<parameter index="3" type="Boolean" optional="true"/>
<parameter index="4" type="Number" optional="true"/>
<parameter index="5" type="Number" optional="true"/>
<metadata name="__go_to_definition_help">
<arg key="pos" value="41308"/>
</metadata>
</method>
<method name="play" declaredBy="fl.video::VideoPlayer" returnType="void">
<parameter index="1" type="String" optional="true"/>
<parameter index="2" type="Number" optional="true"/>
<parameter index="3" type="Boolean" optional="true"/>
<parameter index="4" type="Number" optional="true"/>
<parameter index="5" type="Number" optional="true"/>
<metadata name="__go_to_definition_help">
<arg key="pos" value="34410"/>
</metadata>
</method>
UPDATE: I've updated the library so that you can instantiate an FLVPlayback(w,h) and hence apply skins or whatnot -- treat it just like you would the vPlayer in your code above (except I added the width/height constructor args, since the size used to come from the component on-stage). Instantiate it like so:
var vPlayer:FLVPlayback = new FLVPlayback(640,480);
vPlayer.skin = "http://10.0.1.3/skin.swf"; // optional skin
addChild(vPlayer);
var innerPlayer = vPlayer.getVideoPlayer(vPlayer.activeVideoPlayerIndex);
innerPlayer.load(
"http://10.0.1.3/test.flv"
, 0 // totalTime
, false // isLive
, 5 // startTime
, 5 // duration
);
Note - to use a skin, I compiled one of the FLA examples from Flash CS6... I tried using a skin I found on the Internet and it didn't work - it was likely compiled for an older version. See this skinned screenshot and download my skin.swf.
Good luck, and let me know if you need further info!

Related

How to retrieve a function or method's argument / parameter list from outside the function in Actionscript 3

In another class elsewhere in the code, I want to access the parameters (and their types) of Foo.bar.
The result would contain [ "a", Number ] and [ "b", String ] in one form or another.
public class Foo
{
...
public function bar(a:Number, b:String):void
{
...
}
}
AS3 has a method called describeType
If you call describeType(Foo) on the above example, you'll get:
<type name="Foo" base="Class" isDynamic="true" isFinal="true" isStatic="true">
<extendsClass type="Class"/>
<extendsClass type="Object"/>
<accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
<factory type="Foo">
<extendsClass type="Object"/>
<method name="bar" declaredBy="Foo" returnType="void">
<parameter index="1" type="Number" optional="false"/>
<parameter index="2" type="String" optional="false"/>
<metadata name="__go_to_definition_help">
<arg key="pos" value="51"/>
</metadata>
</method>
<metadata name="__go_to_definition_help">
<arg key="pos" value="23"/>
</metadata>
</factory>
</type>
Now, you can use AS3's XML class and e4x to find the definition of the method with the name bar and grab the parameter elements.

Is there a convenient way to configure noCache and excludeNullProperties parameters for json result in struts2?

I am using struts-json-plugin.2.2.3 for Actions whose result type is json, here is an demo configuration:
<action name="dept_*" class="com.XXX.action.DepartmentAction" method="{1}">
<result name="search">dept_search.jsp</result>
<result name="search_ajax" type="json"><param name="root">deptList</param><param name="excludeNullProperties">true</param><param name="noCache">true</param></result>
<result name="save" type="json"><param name="root">jsonResult</param><param name="excludeNullProperties">true</param><param name="noCache">true</param></result>
<result name="count" type="json"><param name="root">pageCount</param><param name="excludeNullProperties">true</param><param name="noCache">true</param></result>
</action>
This configuration works fine. But for all Actions in my project, noCache and excludeNullProperties have same configuration value just like code above, so I am searching a way to configure them in one place and used for all. I find in JSONInterceptor class, there are same name properties, so I configured like this:
<interceptors>
<interceptor-stack name="ecsStack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="json"><param name="noCache">true</param><param name="excludeNullProperties">true</param><param name="contentType">application/json;charset=utf-8</param></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="ecsStack"></default-interceptor-ref>
And remove same configurations in Action result, but it does not work as expected, there is no cache-control, expires and pragma information in response headers, and null properties are sent to browser.
So why it does not work?
If there is a convenient way to configure these two parameters?
Try this result-type configuration in struts.xml file:
<result-type name="json" class="org.apache.struts2.json.JSONResult">
<param name="noCache">true</param>
<param name="excludeNullProperties">true</param>
</result-type>

how to get a function's info in actionscript?

i often get argument mismatch error ,that usually take me a lot of time to debug program.damn, i really hope i know the function's entrance requirement and where they are come from.
since i only know a function variable is a function,no any other information.
i wrote massive codes like this
public static function call(func:Function,params:Array = null,addToTailIfNotNull:*=null):void{
if (func!=null){
var args:Array =[];
if(params!=null){
args = ArrayTools.clone(params);
}
if (addToTailIfNotNull!=null){
args.push(addToTailIfNotNull);
}
func.apply(null,args);
}
}
i should do things more smartly .
I can suggest you using flash.utils.describeType() method. It returns an XML with a description of an object you passed as a parameter.
Lets say you have a Class:
public class Example {
public function someMethod(number:Number, string:String):void {
}
}
And you call somewhere:
flash.utils.describeType(Example);
You should get an XML with something like this in there:
<method name="someMethod" declaredBy="com.example::Example" returnType="void">
<parameter index="1" type="Number" optional="false"/>
<parameter index="2" type="String" optional="false"/>
<metadata name="__go_to_definition_help">
<arg key="pos" value="501"/>
</metadata>
</method>
I am not sure that this is what you looking for, as in your example if you pass you Function argument there you will get a description of Function class:
<type name="builtin.as$0::MethodClosure" base="Function" isDynamic="false" isFinal="true" isStatic="false">
<extendsClass type="Function"/>
<extendsClass type="Object"/>
<accessor name="length" access="readonly" type="int" declaredBy="Function"/>
<accessor name="prototype" access="readwrite" type="*" declaredBy="builtin.as$0::MethodClosure"/>
</type>
But maybe you can refactor you "call" method so it could get the right description (for example pass additional info into it - like an object class and a method name - so you could analyse the method signature in it. Not the most beautiful solution, but still...)

AS3 Error: Access of possibly undefined property STANDARD_OUTPUT_DATA through a reference with static type Class

I have a Flex AIR project that compiles and runs in Flex Builder 4.6. I'm trying to create an Ant script that will build the project. On these lines I get these errors:
_process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
_process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
_process.addEventListener(NativeProcessExitEvent.EXIT, onNativeProcessExit);
I'm getting this error:
[mxmlc] MyClass.as(190): col: 44 Error: Access of possibly undefined property STANDARD_OUTPUT_DATA through a reference with static type Class.
[mxmlc] _process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
[mxmlc] ^
[mxmlc] MyClass.as(191): col: 44 Error: Access of possibly undefined property STANDARD_INPUT_PROGRESS through a reference with static type Class.
[mxmlc] _process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
From what I can tell, these are defined in frameworks/libs/air/airglobal.swc. I think I'm including that with the compiler.external-library-path element below.
The compile target of my build.xml ant script looks like this:
<target name="compile" depends="init">
<mxmlc file="${MAIN_SOURCE_FILE}" output="${DEPLOY_DIR}/${APP_NAME}.swf"
services="${APP_ROOT}/services/flex/services-config.xml">
<swf-version>13</swf-version>
<locale>en_US</locale>
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${APP_ROOT}/../MyLib/src"/>
<source-path path-element="${APP_ROOT}/src"/>
<compiler.external-library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs/air" />
</compiler.external-library-path>
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
<include name="../bundles/{locale}" />
</compiler.library-path>
<compiler.library-path dir="${APP_ROOT}" append="true">
<include name="libs" />
<include name="libs/player" />
</compiler.library-path>
<define name="CONFIG::debugging" value="false"/>
<compiler.debug>false</compiler.debug>
</mxmlc>
I think you want to change the <load-config> to be one of these:
<load-config filename="${FLEX_HOME}/frameworks/air-config.xml"/>
or
<load-config filename="${FLEX_HOME}/frameworks/airmobile-config.xml"/>

Actionscript 3 Vector Number does not extend Vector *

I am currently being confused by the Vector class.
I wrote a beautiful XML to TypedClass parser. Works beautifully and without fault. UNTIL a co-worker noticed we got a Conversion Error for Vector.<Number> to Vector.<*>.
Every Vector I've ever tested all extend Vector.<*>.
Vector.<Sprite>, Vector.<String>, Vector.<Point>, Vector.<Boolean>, Vector.<TextField>, Vector.<CustomObject>, etc etc etc. ALL of them.
<type name="__AS3__.vec::Vector.<String>" base="__AS3__.vec::Vector.<*>" isDynamic="true" isFinal="false" isStatic="false">
<extendsClass type="__AS3__.vec::Vector.<*>"/>
<extendsClass type="Object"/>
<accessor name="length" access="readwrite" type="uint" declaredBy="__AS3__.vec::Vector.<*>"/>
<accessor name="fixed" access="readwrite" type="Boolean" declaredBy="__AS3__.vec::Vector.<*>"/>
</type>
But then when I use describeType on Vector.<Number>, Vector.<uint> and Vector.<int>.
<type name="__AS3__.vec::Vector.<Number>" base="Object" isDynamic="true" isFinal="true" isStatic="false">
<extendsClass type="Object"/>
<constructor>
<parameter index="1" type="uint" optional="true"/>
<parameter index="2" type="Boolean" optional="true"/>
</constructor>
<accessor name="length" access="readwrite" type="uint" declaredBy="__AS3__.vec::Vector.<Number>"/>
<accessor name="fixed" access="readwrite" type="Boolean" declaredBy="__AS3__.vec::Vector.<Number>"/>
</type>
Now I have accounted for these 3 vectors individually as even uint and int does not extend Vector.<Number> as I would have expected.
And my parsing function works for all types correctly again. But my confusion comes as to WHY this is the case, and why I couldn't find any documentation on the subject.
I asked the same question on the Kirupa forums a few months back, but I cannot for the life of me find the thread.
If I remember this correctly, the Vector.<Number>, Vector.<int>, and Vector.<uint> (but not Boolean or String, oddly enough) classes are made to be as fast as possible, so they are written and treated as separate classes by the Flash Player.
As you have noticed, all other Vector classes extend Vector.<*> and type checking is done a bit differently (which is why Vectors are faster with int, uint, and Number, but Arrays are slightly faster for all other classes)
Anyway, that was the WHY. As for how to get around this issue, I'm afraid you are going to have to pass your vector as untyped to the function you want to use it in:
public function addItem(vector:*, item:*)
{ vector.push(item); }