Schemaphic Systems Blog

Sharing experiences in Flash, Flex and AIR

Layout mirroring in Flex4

with 3 comments

Today I came across a strange problem (mostly due to lack of knowledge in LayoutDirection.as).
I had a mx.controls.VideoDisplay component in a class which extends Sprite in Flex4.
Now when I add the videoDisplay to the container, I found that the video did not show up, but the sound was playing in behind, which suggests that the visual elements are not added.
After a long search I found that I was just trying to add a UIComponent to a Sprite which is not at all possible. And I am sure some of the developers like me also faces the same problem for the first time (though a silly mistake).
So I added spark.core.SpriteVisualElement and added the video to it and it started showing.

Now the actual stuff, to my surprise the video was showing flipped. After much pondering over net and studying the UIComponent class I came to know about the LayoutDirection class, by which any UIComponent and IVisualElement can be flipped. A detailed explanation of the same can be found here.

Here is the code snippet I used.

import mx.controls.VideoDisplay;
import mx.events.VideoEvent;
import spark.core.SpriteVisualElement;
import mx.core.LayoutDirection;

var container:SpriteVisualElement = new SpriteVisualElement();
var fPlayer:VideoDisplay = new VideoDisplay();
fPlayer.maintainAspectRatio = true;
fPlayer.width = 600;
fPlayer.height = 400;
fPlayer.layoutDirection = LayoutDirection.LTR;
container.addChild( fPlayer);
Advertisements

Written by Deepanjan Das

March 17, 2011 at 10:30 AM

Posted in ActionScript3.0

3 Responses

Subscribe to comments with RSS.

  1. Hi,

    have you maybe tried flipping a scaled visual element? When I was trying to make our project work for arabic countries I had immense Problems with that. I found out that it was actually a bug in the Flex framework, because when flipping scaled content the center of reference for the scaling operation isn’t flipped. I posted the issue in several forums (also Adobe’s own) but didn’t get any response so far.

    Felix

    March 17, 2011 at 1:58 PM

    • First I tried to flip is by using scale *= -1; and obj.x += obj.width; that caused a concern with the registration point for the object.
      Then I removed the scaling code and used the layoutDirection. My content is not scaled, so might be did not see the issue you faced.

      Is there any way I can reproduce the error you faced.

      DD

      Deepanjan Das

      March 17, 2011 at 2:09 PM

      • Ok so the issue might be (hopefully) fixed. Can’t test it at the moment. We had problems with _every_ scaled and flipped image content.

        Felix

        March 17, 2011 at 2:11 PM


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: