Get the Flex 3.5 client library from the Kaltura TestMe Console
The Kaltura API Client Library for Adobe Flex Applications.
Follow the following guidelines when creating Kaltura based Flex applications.
Using the client library
- Download or check out the code from SVN (alternatively, use the generator to generate the client from latest API schema)
- Import the project as a Flash Builder project
- Create a configuration object and fill your partner details
- Instantiate a Client object and use it to post the requests
To start off, we need to initialize the Kaltura client that we'll be using to make the Kaltura calls:
Create a KalturaConfig object, fill it's members with values and create a new KalturaClient passing the constructor the config object.
The next thing we'll need to make calls to the Kaltura APIs, is the Kaltura Session. Usually, a KS will be provided through flashvars from a server application to protected the partner secret keys.
If the KS, userId and the rest of the partner info is being passed through flashvars, make sure to set these values to the client via the configuration object and directly to the client
To create a KS, use the SessionStart API action. Create a SessionStart object, passing it the partner secret, the actual userId , the type of the session and the partner id. Listen to the complete and fail events and call the request by passing the SessionStart to the client post method.
private function init() : void
{
var configuration : KalturaConfig = new KalturaConfig();
configuration.partnerId = "309";
configuration.domain = "http://www.kaltura.com";
configuration.srvUrl = "api_v3/index.php";
_kc = new KalturaClient( configuration );
cursorManager.setBusyCursor();
var startSession : SessionStart = new SessionStart( "secret key here" ,"anonymouse" ,KalturaSessionType.ADMIN);
startSession.addEventListener( KalturaEvent.COMPLETE , onSessionStart );
startSession.addEventListener( KalturaEvent.FAILED , onFailed );
_kc.post( startSession );
}
private function onSessionStart( event : KalturaEvent ) : void
{
cursorManager.removeAllCursors();
event.target.removeEventListener( KalturaEvent.COMPLETE , onSessionStart );
event.target.removeEventListener( KalturaEvent.FAILED , onFailed );
//It is important we set the KS to the client before making any other requests to the APIs -
//this will make certain every request will be carried out caring the ks.
_kc.ks = event.data as String;
mainPanel.enabled = true;
var kw : KalturaWidget = new KalturaWidget();
}
MultiRequest - joining related requests to reduce callbacks
Multirequest - an aggregated list of API requests that will be performed as a single request to the server.
Use a Multirequest to reduce the ammount of client-server callbacks when multiple number of API calls should be combined.
To perform a Multirequest, we create a Multirequest object.
Create the objects of the API requests we want to perform inside the Multirequest, and add them to the created Multirequest object using the addAction method.
Then, we map paramteres that will be used between the requests; on this example we want to use id of the first object from the first response as the value of the entryId parameter for the second request.
After all actions added and mapping completed, we listen to the complete and fail events of the Multirequest. And to call the request - we use the post method on the client.
{
cursorManager.setBusyCursor();
var mr : MultiRequest = new MultiRequest();
var mediaList : MediaList = new MediaList();
mr.addAction( mediaList );
var mediaGet : MediaGet = new MediaGet( "" );
mr.addAction( mediaGet );
mr.mapMultiRequestParam( 1, "objects:1:id" , 2 , "entryId" );
mr.addEventListener( KalturaEvent.COMPLETE , onMultiComplete );
mr.addEventListener( KalturaEvent.FAILED , onFailed );
_kc.post( mr );
}
/**
* Handler to the multirequest API action.
* We use the data carried by the event to use the result of the API action.
* Note, that the result of multirequest is actually an Array that contains an aggregated results list of the
* actions requested in the multirequest
**/
private function onMultiComplete( event : KalturaEvent ) : void
{
var resArr : Array = event.data as Array;
var mediaListResponse : KalturaMediaListResponse = (resArr[0] as KalturaMediaListResponse);
//use the returned objects array as the dataprovider for a data grid:
dg.dataProvider = new ArrayCollection( mediaListResponse.objects );
cursorManager.removeAllCursors();
}



