Arabic text in as3 - actionscript-3

How can I display arabic text from right to left with as3?

This code will do the trick:
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.external.*
import fl.text.TLFTextField;
import flash.text.TextFormat;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.textLayout.elements.TextFlow;
var arabicTextField:TLFTextField = new TLFTextField();
arabicTextField.antiAliasType = AntiAliasType.ADVANCED;
arabicTextField.mouseEnabled = false;
arabicTextField.selectable = false;
arabicTextField.direction = flashx.textLayout.formats.Direction.RTL;
var fmt:TextFormat = new TextFormat();
fmt.color = 0xFFFFFF;
fmt.font = "arialArabic"
arabicTextField.embedFonts = false;
arabicTextField.defaultTextFormat = fmt;
arabicTextField.setTextFormat(fmt);

The Text Layout Framework can handle right to left text.

I know this is an old thread. But still the most useful snippet around for RTL Text. Thanks Ellen.
Let me add some experiences in coding for iOS on Flash Builder 4.7 in times of CC:
Flash Builder doesn't ship with the TLFTextField and its supporting classes needed to display Arabic and other RTL languages on iOS.
Between CS6 and CC Adobe has even dropped those classes from Flash Professional. Probably because the standard TextField class has been improved.
Still, on iOS RTL and and Arabic Ligatures will not work out of the Box. If you use the TextField class AirSimulator of FlashBuilder will display correctly. Not if you run the same code on iOS.
StageText and its NativeText wrapper will render correctly but do have disadvantages for static text.
You might think of reintroducing TLFTextField. Here's how you can do it:
Install Flash Professional CS6 (!) from the Creative Cloud
In the "libs" subfolder of the programfolder you'll find two SWCs that contain the classes needed to use TLFTextField: TLFRuntime.swc & textLayout.swc
Copy the SWC in your ProjectFolder and include it in Flash Builder by opening your project's properties -> ActionScript Build Path -> Library Path -> Add SWC (or Add SWC-Folder)
This should make Ellen's code work on FlashBuilder 4.7 for iOS with Air SDK 3.9
You could probably expect the standard TextField display Arabic and other RTL languages correctly in future releases of Air.

Additionally, you probably will need to include the fonts you use in your library

try to add textformat with propriety right alignment
var txtFormat:TextFormat = new TextFormat();
txtFormat.align = "right";

I've also had success with FlarabySWF - it costs some money (not alot) but it actually works quite well in my experience.

If you're not opposed to the flex framework, it now includes a decent internationalization library that should allow you to do this easily. Here's a decent place to get started http://devgirl.org/2011/03/15/flex-4-localization/

Related

ActionScript3 DataGrid how to display content on browser

Thanks very much for being the most answered community on the web.
I have this small problem:
I want to read a database using Tomcat Servlets into a ActionScript DataGrid.
Please mind that I want it to be pure ActionScript; no mix with MXML.
I have already done a exercise with MXML and DataGrid but it is not meeting my requirement.
I want to understand how to use ActionScript libraries.
thanks for listening
Here is the code:
package {
import flash.display.*;
import spark.components.DataGrid;
import mx.collections.ArrayList;
public class EmpDBDebug extends Sprite {
public var empDG:DataGrid;
public var DGArray:Array = [
{Album:'Slanted and Enchanted'},
{Album:'Brighten the Corners'}];
public var DGArrayList:ArrayList;
public function EmpDBDebug() {
empDG = new DataGrid();
DGArrayList = new ArrayList(DGArray);
empDG.dataProvider = DGArrayList;
addChild(empDG);
}
}
}
This is a simplified version of what I want to do. I have replace Servlet with Array. All I want to do is display the DataGrid content on browser. I am not able to do that. It is refreshing but everything is blank. Hope I am doing something wrong. I tried everything. I replace Sprite with Stage but still nothing works.
Since I want to do it in pure ActionScript without using MXML, are there any other libraries which I should be using. And again I am mostly using Notepad++ and MonsterDebugger. I do not have access to fl.data.DataProvider libraries. Let us rule it for the time being. I am bit confused with Flash Licensing. Can I do it with Apache Flex?
Can you throw some light.
thanks again
RR23850

FlashBuilder 4.6 mx.controls.Button missing?

Im writing my first application in Flash Builder but I have much experience with Flash. I and trying to use the button class in flash builder but my error says "the imports button could not be found". I tried importing flash.display, flash.ui to see it Button was hidden somewhere else. The point is to dynamically load buttons and their labels via xml. Any help is appreciated. Thanks!
<fx:Script>
<![CDATA[
import flash.events.*;
import mx.controls.Button;
private function doAdd(e:Event):void {
var buttonList:XMLList = new XMLList(cutsXML.cut.#name);
for(var i=0; i<buttonList.length(); i++){
var btn:Button = new Button();
btn.label = buttonList[i];
buttonBox.addElement(btn);
}
}
]]>
</fx:Script>
<s:VGroup left="30" right="30" top="50" bottom="30" id="buttonBox">
</s:VGroup>
Im guessing you are creating a mobile app? As mx components are not available (by default) in mobile apps.
You can either use the spark button - spark.components.Button - or manually include the mx components by importing the mx.swc library (found within flex sdk)
Add the mx.swc to your project, that'll do.
In Flash Builder 6.0, do the following:
Right-click on the project in the Package Explorer perspective
Properties...
Flex Build Path (in the left side navigation pane)
Click Add SWC...
Find the mx.swc on your box. On OSX at the time of this writing it was:
/Applications/Adobe Flash Builder 4.6/sdks/4.6.0/frameworks/libs/mx/mx.swc
Click OK
Rebuild your project

How to create an Alert Dialog in Actionscript 3 without the Flex Framework in a standalone AIR application designed to run on Windows

I've got a project, written in Actionscript 3, built using Flash CS5. In it, there are sections that require a microphone to be plugged in and the programmer who preceded me notified the user of the lack of microphone by throwing an Error. This causes the program to stop running, a behavior which in undesirable.
The question: How to create a popup alert dialog in as pure as possible Actionscript. I've found the Alert class in mx.controls, but I can't find a way to add it to the project. I found the Yahoo AlertManager class, but couldn't get it to work properly and it looks like the framework around it is larger than I need.
This is deployed on touchscreens as a standalone application on a Windows 7 Environment using AIR 2.5, Flash CS5, Actionscript 3.0. I use FlashDevelop as the AS editor.
You'll have to make your own alert box, either by making NativeWindow instance and editing it, or (what I would recommend) making your own custom class that extends NativeWindow.
This is a simple generalized version of one that I made for one of my apps:
package
{
import flash.display.*;
import flash.geom.*;
public class AlertWindow extends NativeWindow
{
public function AlertWindow(owningWindow:NativeWindow, windowTitle:String)
{
var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
initOptions.maximizable = false;
initOptions.minimizable = false;
initOptions.resizable = false;
initOptions.owner = owningWindow;
initOptions.type = NativeWindowType.UTILITY;
super(initOptions);
title = windowTitle;
alwaysInFront = true;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
bounds = new Rectangle(owner.x + owner.width - (owner.width / 2) - 125, owner.y + owner.height - (owner.height / 2) - 75, 250, 150);
}
}
}
I whipped it up fairly quickly so it might not be as clean or efficient as it could be but it should be a good base to start on. Obviously you can add stuff like messages, buttons, event listeners, and anything else.
If you don't understand all of the code you should check out the NativeWindow and NativeWindowInitOptions documentation.

Using Squiggly in Flash CS5

This is going to seem quite a lame question - basically we have downloaded a package called Squiggly - http://labs.adobe.com/technologies/squiggly/ - and we are trying to implement it into Flash (using AS3, CS5). And none of us are very good at flash, and have no clue how to do it, the actionscript in the .as is as follows:
package
{
import flash.display.Sprite;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.edit.EditManager;
import com.adobe.linguistics.spelling.SpellUIForTLF;
public class SquigglyTLFExample extends Sprite
{
public function SquigglyTLFExample()
{
var markup:XML = <TextFlow xmlns='http://ns.adobe.com/textLayout/2008'><p><span>I know </span><span fontStyle='italic'>Enlish</span><span>. Use the context menu to see the suggestions of the missbelled word.</span></p></TextFlow>;
var textFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);
textFlow.flowComposer.addController(new ContainerController(this, 500, 600));
textFlow.flowComposer.updateAllControllers();
textFlow.interactionManager = new EditManager();
SpellUIForTLF.enableSpelling(textFlow, "en_US");
}
}
}
I have a blank swf, and just want to know how to implement it to a text area. Why do people still use flash? :(
Here's how I got it running in a new FLA file in Flash CS 5:
1) In Flash, go into 'Advanced Actionscript 3.0 Settings' and change to the Librarys path tab on the middle of that pane.
2) Add the AdobeSpellingUITLF.swc.
3) When the SWC has been added, select it in the list and click the little 'I'-icon(when you hover it, it should say: 'Set linkage options for a library').
Change the link type to 'Merged into code'.
4) Add the code you posted (SquigglyTLFExample) as your Document class.
5) Remember to copy the 'AdobeSpellingConfig.xml' and the 'dictionaries'-folder to the same folder as the generated SWF-file.
The configuration in Flash should look something like this:
i have built a class based on squiggle a while ago: http://apdevblog.com/actionscript-spell-checking-with-squiggly-as3-only-and-flash-9-compatible/
it's very easy to use and compatible with normal textfields >flash9.
cheers

FLVPlayback, go fullscreen smooth?

Im looking into using and customizing FLVPlayback in a project. How to go about this is clear, but I noticed 1 anoying thing. When going fullscreen, first Flash player goes fullscreen and then briefly shows the FLVPlayback component in its original size, before jumping to show the video itself fullscreen.
I noticed on Youtube this doesnt happen. How can I escape this 'flicker' and have the video go fullscreen as the videos do on youtube?
Thanks a lot for any tips!
Marcel
in general FLVPlayback along with most of the components built into flash are junk. You are much better off building your own flv player using the NetConnection and NetStream class. Build it once well and generic enough to edit the control visuals and you have yourself a bullet proof flv player for all your projects.
http://actionscriptexamples.com/2008/02/26/loading-flv-files-in-actionscript-30-using-the-netconnection-and-netstream-classes/
Just to say I've used FLVPlayback on jobs many times, and sure it's buggy, but I've never seen this problem. You can definitely fix it. How are you going fullscreen? I've recently being doing something like this...
import flash.display.*;
import flash.events.*;
import fl.video.*;
import flash.geom.Rectangle;
.
.
.
myFLVPlayback.fullScreenTakeOver = false;
mc.stage.fullScreenSourceRect = new Rectangle(0,0,480,360);
myFullScreenButton.addEventListener(MouseEvent.CLICK, onFullScreenButtonClicked);
private function onFullScreenButtonClicked(e:MouseEvent):void {
mc.stage.displayState = StageDisplayState.FULLSCREEN;
}
(though i appreciate you might be using the fullscreen button in an FLVPlayback skin, so this might not be perfect)
NOTE: I just hammered that code in so it might not be perfect/complete. Hopefully you'll find it useful.
++ i'd make sure you set the size and scale of your flvplayback too, e.g. myflvplayback.setSize(w,h)
++ how about myflvplayback.scaleMode = VideoScaleMode.NO_SCALE;