Tag Archives: flex 3

Flex 3 NetStream video rotation

Why should I rotate a video stream?

Well if you’d like to make some video upload application, let’s assume someone makes a video with it’s phone. The case with a video camera is not the same, almost every camera adjusts it’s rotation correctly, but when it comes to your mobile not always the video contains information about the rotation.

The problem is when the user uploads a rotated video, how I’d rotate it back on the correct position when playing it with a simple FLV player.

The answer is so simple!

You can just use this simple chunk of code:

...
_video = new Video();
_video.rotation = 90;
...

and thus you can rotate the video with several degrees.

Tips and tricks in ExternalInterface communication!

ActionScript and the rest of the world

In the past, when ActionScript v2 was widely used, the most common way to interact with the other parts of the web application, whether a page refresh, redirect or JavaScript method call was the as2 method getURL. With the simple getURL(‘javascript:someJSMethod…’) the flash movie called the JS function and everything was OK.

Now in ActionScript v3 where everything looks and it is different, everything about communication between JS and Flash/Flex is done by ExternalInterface. The communication can be done in both directions. From JS to Flash and vice versa.

The ExternalInterface.call

There are two simple methods implemented by ExternalInteface. The first one is addCallback and the second one is call. Here I’m going to write a little more about the second one.

The most common usage is:

ExternalInterface.call('jsMethod');

where jsMethod is, as you can guess, a JavaScript method. Something like:

test.js

function jsMethod() { alert('test') };

A bit different, but yet again simple, is the call to a js function with parameters:

ExternalInterface.call('jsMethod', param1, param2);

where the javascript function can be:

function jsMethod(param1, param2) { alert(param1) };

But what I was writing about is really tricky. What if the jsMethod returns a value? Than in the .js file you’ve the following method:

function jsMethod() { return 'foo bar' };

and when you try this:

var str:String = ExternalInterface.call('jsMethod');
Alert.show(str);

you get the alert box with the string ‘foo bar’.

Where to use it?

Well this is really useful, because you get the response within the call method, only with the .call instead with .call and than .addCallback. The problem of course appears when you try to use it with AJAX call. Than even if the function returns in the success method of the AJAX call the flash doesn’t get the response.

Than you simply implement the communication with both .call and .addCallback!

Flex 3 DateChooser UTC issue

What I intend to do

The task can be described as it is. There’s a Flex 3 DateChooser component integrated with a custom timeline component. The problem occurs when exporting the data from the flash to the browser. Than I write the unix timestamp to the url of the browser. Of course I’m using date.getTime() in Flex.

getTime()

Applying getTime() to any object of type Date in Flex results in a unix timestamp with included milliseconds. Of course the server side technology which in our case is PHP should devide by 1000 to remove the milliseconds. Continue reading Flex 3 DateChooser UTC issue

Flex 3: compare two dates

Theory of Operation

You’re using Flex 3 and want to compare two dates. The format of the dates is string something like “2009 May 05”. The question is …

What’s the best way to compare them

Well if you’ve the dates as strings and you can easily conver them to something like unix timestamps. If they are a Date object you can try lik so: Continue reading Flex 3: compare two dates

Flex 3 HSlider thumb gap issue

Introduction to the problem

When the HSlider is set up with two or more thumbs there’s a gap between them always. The problem is that you may want to put them on one single value of the slider, but it’s not possible.

First: hide your thumbs

The quick solution is to make custom skin for the thumbs, setup the height and width of the thumb to be 1px and make a transparent background image for skinning them. That of course does not solve the problem. There’s still gap of 1 value between the thumbs, and still you cannot select one single value with both of them. Continue reading Flex 3 HSlider thumb gap issue