Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Flash reading Arabic

Posted on 2009-07-11
12
Medium Priority
?
297 Views
Last Modified: 2012-05-07
Hi experts,
I have a flash components downloaded from one of the websites on the internet "Flashden.net" It's an image viewer and it's great. I want to integrate this FC with my CMS, so I linked that FC data source with a .php file and it worked just fine except that it doesn't read Arabic font. !! I tried all possible solutions like:
1. Add this : System.useCodePage=true; to the first line of the .as reading data file.
2. I tried all the unicode possibilities and I'm sure that my data is UTF8 compatible
3. I changed the first line of the .xml file into many different enicodes as well.

All of which didn't work with me and the best result I got is that the Arabic font turnes into "????????". Could anyone tell me what to do please?

You can download the source files form here:
http://www.shopies.com/flashden_xml-product-viewer-as3_38951.zip

Best Regards,
0
Comment
Question by:Shopies
  • 6
  • 5
12 Comments
 
LVL 14

Expert Comment

by:TanLiHao
ID: 24829976
Embed the arabic fonts.
0
 

Author Comment

by:Shopies
ID: 24830070
I embeded the font as instructed in the first link but it didn't work. It gave me several errors when I came to export the file. Here is the code I used:
package {
import flash.display.Sprite;
 
import flash.text.Font;
 
public class FontFileGoudy extends Sprite
{
 
//here image/Goudy.ttf points to the font file relative to this file
[Embed(source="Arial.ttf", fontName="Goudy",fontWeight="bold", mimeType="application/x-font-truetype")]
private var font1:Class;
 
public function fontFile()
{
trace(Embedded font in loaded swf);
 
Font.registerFont(font1);//registers font
 
trace(registered font);
}
}
}

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:TanLiHao
ID: 24830098
Show the code on how you integrate with the CMS.

Also show the errors.
0
 

Author Comment

by:Shopies
ID: 24830137
Okay, below you will see the PHP code:
And the errors I get when I export the .fla file into .swf is attached
 
 

FUNCTION update_xml()
	{
		require "config.php";
		include_once "class.TemplatePower.inc.php";
		
		$tpl = new TemplatePower("components/product_viewer/items.xml");
		$tpl -> prepare();
		
		include_once 'ez_sql_core.php';
		include_once 'ez_sql_mysql.php';
		
		$ez = new ezSQL_mysql($config['db_user'],$config['db_password'],$config['db_name'],$config['db_server']);
		$ez->query("SET NAMES cp1256");
		
		IF($products_list = $ez->get_results("SELECT id,title,picture,details FROM album ORDER BY id DESC LIMIT 3",ARRAY_A))
		{
		FOREACH($products_list AS $rows)
		{
			$tpl -> newBlock("items");
			$tpl -> assign($rows);	
		}
		}
 
		$xmlfile = fopen("components/product_viewer/products.xml",'w+');		
		$xmlfile = fwrite($xmlfile,$tpl->getOutputContent());
		
	}

Open in new window

flash-error.jpg
0
 
LVL 14

Accepted Solution

by:
TanLiHao earned 2000 total points
ID: 24830151
No I don't need the PHP code, I just want to see how you used the component.

The errors are caused because you put the code on a frame instead in a .as file. However, anyway just post how you use the component, not the php code, but the as code.
0
 

Author Comment

by:Shopies
ID: 24830185
I don't know what do you mean by the .as code? If you mean the FC .as file then you could find it below, but if you mean how do I embed the FC in my CMS then I just use an iframe.!! Does this answer your question?>
package com.ronnieswietek.productslider
{
	
	/**
	* Note: This file uses the free tweening engine: TweenLite. 
	* I have direct permission from Jack Doyle(Author of TweenLite to
	* distribute TweenLite, TweenFilterLite or TweenMax with any of my 
	* files on flashden). Please download it here if you have to:
	* http://blog.greensock.com/tweenliteas3/
	*
	* Please view help.txt for information on how to setup a product slider
	*/
	
	// Import neccessary class files used in this product slider class
	import gs.TweenFilterLite;
	import gs.TweenLite;
	import gs.easing.Expo;
	
	import flash.display.*;
	import flash.events.*;
	import flash.display.BlendMode;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.net.navigateToURL;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
 
	public class ProductSlider extends MovieClip
	{
		
		// Private variables that should not be changed!
		// Everything set here is in the XML
		
		private var yPos					:Number;
		private var imageSpacing			:Number;
		private var slideTweenDuration		:Number;
		private var blurInDuration			:Number;
		private var blurOutDuration			:Number;
		
		private var newX					:Number = 0;
		private var currentIndex			:Number = 0;
		private var prevIndex				:Number = 0;
		
		private var product					:MovieClip;
		private var nextBtn					:MovieClip;
		private var prevBtn					:MovieClip;
		private var mainHolder				:MovieClip;
		
		private var titleField				:TextField;
		private var subtitleField			:TextField;
		
		private var source					:String;
		private var title					:String;
		private var subtitle				:String;
		private var itemURL					:String;
		private var useMouseWheel			:String;
		
		private var temp					:Object;
		private var data					:Array;
		private var xmlData					:XML;
		private var xmlList					:XMLList;
		private var xmlLoader				:URLLoader;
 
		public function ProductSlider(xml:String)
		{
			// Load the XML
			xmlLoader						= new URLLoader();
			xmlLoader.load(new URLRequest(xml));
			xmlLoader.addEventListener(Event.COMPLETE, onComplete);
		}
		
		private function onComplete(e:Event):void
		{
			// Setup the movie clips for ease of access.
			mainHolder						= (parent as MovieClip).mainHolder;
			nextBtn							= (parent as MovieClip).next;
			prevBtn							= (parent as MovieClip).prev;
			titleField						= (parent as MovieClip).titletxt;
			subtitleField					= (parent as MovieClip).subtitletxt;
			
			// The data array contains all of the XML for easy access to the data anywhere.
			data							= new Array();
			xmlData							= new XML(xmlLoader.data);
			xmlList							= new XMLList(xmlData.item);
			
			yPos							= xmlData.attribute("yPosition");
			imageSpacing					= xmlData.attribute("imageSpacing");
			useMouseWheel					= xmlData.attribute("useMouseWheel");
			slideTweenDuration				= xmlData.attribute("slideTweenDuration");
			blurInDuration					= xmlData.attribute("blurInDuration");
			blurOutDuration					= xmlData.attribute("blurOutDuration");
			
			for (var i:int = 0; i < xmlList.length(); i++)
			{
				// Loop through the xml and store it to the data array.
				temp						= new Object();
				
				source						= xmlList[i].@source
				title						= xmlList[i].@title;
				subtitle					= xmlList[i].@subtitle;
				itemURL						= xmlList[i].@itemURL;
				temp.source					= source;
				temp.title					= title;
				temp.subtitle				= subtitle;
				temp.itemURL				= itemURL;
				
				data.push(temp);
			}
			// Initiate the products!
			initProducts();
		}
		
		private function initProducts():void
		{
			for (var i:int = 0; i < data.length; i++)
			{
				// new ProductHolder() is the movie clip found in the library with linkage id of ProductHolder.
				// Each product will be inside one of these.
				product						= new MovieClip();
				product.x					= imageSpacing + (i * imageSpacing);
				product.id					= i;
				mainHolder.y				= yPos;
				
				var imgRequest:URLRequest 	= new URLRequest(data[i].source);
				var imgLoader:Loader 		= new Loader();
				
				product.buttonMode			= true;
				product.useHandCursor		= true;
				product.addEventListener(MouseEvent.CLICK, launchProductURL);
				
				if (useMouseWheel == "true")
				{
					// if useMouseWheel is true in the XML you will be able to scroll the products with the mouse wheel.
					stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheelEvent);
				}
				
				imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
				imgLoader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
				imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
				imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandler);
				
				imgLoader.load(imgRequest);
				
				mainHolder.addChild(product);
				product.addChild(imgLoader);
				
			}
			// setup events for the arrows
			prevBtn.addEventListener(MouseEvent.CLICK, moveItemsLeft);
			prevBtn.addEventListener(MouseEvent.ROLL_OVER, navigationOver);
			prevBtn.addEventListener(MouseEvent.ROLL_OUT, navigationOut);
			prevBtn.buttonMode				= true;
			prevBtn.useHandCursor			= true;
			
			nextBtn.addEventListener(MouseEvent.CLICK, moveItemsRight);
			nextBtn.addEventListener(MouseEvent.ROLL_OVER, navigationOver);
			nextBtn.addEventListener(MouseEvent.ROLL_OUT, navigationOut);
			nextBtn.buttonMode				= true;
			nextBtn.useHandCursor			= true;
			
			titleField.mouseEnabled			= false;
			subtitleField.mouseEnabled		= false;
			
			loadText(currentIndex);
		}
		
		private function navigationOver(e:MouseEvent):void
		{
			TweenLite.to(e.currentTarget.arrow,0.5,{alpha:0.9,ease:Expo.easeOut});
			TweenLite.to(e.currentTarget.bar,0.5,{alpha:0.4,ease:Expo.easeOut});
		}
		
		private function navigationOut(e:MouseEvent):void
		{
			TweenLite.to(e.currentTarget.arrow,0.5,{alpha:0.2,ease:Expo.easeOut});
			TweenLite.to(e.currentTarget.bar,0.5,{alpha:0,ease:Expo.easeOut});
		}
		
		private function launchProductURL(e:MouseEvent):void
		{
			// This function gets called when you click on a product
			navigateToURL(new URLRequest(data[e.currentTarget.id].itemURL),"_blank");
		}
		
		private function loadText(itemID:Number):void
		{
			// Blur the text and change it to the correct text
			TweenFilterLite.to(titleField,blurInDuration,{blurFilter:{blurX:10, blurY:10, quality:3}});
			TweenFilterLite.to(subtitleField,blurInDuration,{blurFilter:{blurX:10, blurY:10, quality:3},onComplete:undoBlur});
			titleField.text					= data[itemID].title;
			subtitleField.text				= data[itemID].subtitle;
			
			//Slide the arrows over to accomidate subtitle field width change
			subtitleField.autoSize			= TextFieldAutoSize.CENTER;
		}
		
		private function undoBlur():void
		{
			// Now unblur the text
			TweenFilterLite.to(titleField,blurOutDuration,{blurFilter:{blurX:0, blurY:0, quality:3}});
			TweenFilterLite.to(subtitleField,blurOutDuration,{blurFilter:{blurX:0, blurY:0, quality:3}});
		}
		
		private function moveItemsRight(e:MouseEvent):void
		{
			currentIndex 					+= 1;
			
			if (currentIndex > (data.length - 1))
			{
				// End of the product line
				currentIndex 				= (data.length - 1);
			}
			else
			{
				// Slide mainHolder to show next product
				newX						= Math.round(currentIndex * (imageSpacing * -1));
				TweenLite.to(mainHolder,slideTweenDuration,{x:newX,ease:Expo.easeOut});
				loadText(currentIndex);
			}
		}
		
		private function moveItemsLeft(e:MouseEvent):void
		{
			currentIndex					-= 1;
			
			if (currentIndex < 0)
			{
				// Beginning of the product line
				currentIndex = 0;
			}
			else
			{
				// Slide mainHolder to show next product
				newX						= Math.round(currentIndex * (imageSpacing * -1));
				TweenLite.to(mainHolder,slideTweenDuration,{x:newX,ease:Expo.easeOut});
				loadText(currentIndex);
			}
		}
		
		private function mouseWheelEvent(e:MouseEvent):void
		{
			// slide the items by the mouse wheel
			if (e.delta > 0)
			{
				moveItemsLeft(null);
			}
			else
			{
				moveItemsRight(null);
			}
		}
		
		private function initHandler(e:Event):void
		{
			// After the image is done loading, set its alpha to 0 and set its registration point to the middle horizontally.
			e.target.content.alpha			= 0;
			e.target.content.x				= -e.target.content.width * 0.5;
		}
		
		private function completeHandler(e:Event):void
		{
			// After the init call, fade the image in.
			TweenLite.to(e.target.content,1.5,{alpha:1,ease:Expo.easeOut});
		}
		
		private function progressHandler(e:ProgressEvent):void
		{
			// You can do what you like with this progress event. It just tells the status of loading image 0%-100%.
			//trace(e.bytesLoaded / e.bytesTotal);
		}
		
		private function ioErrorHandler(e:IOErrorEvent):void
		{
			trace("invalid source url");
		}
 
	}
	
}

Open in new window

0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 24833282
Can you link me to your site? I would like to see the ??? text.
0
 

Author Comment

by:Shopies
ID: 24833620
I'm working locally. I gave you the complete source to download in my first post. Do you want me to attach the .php file?
0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 24833672
I need your .xml file.
0
 

Author Comment

by:Shopies
ID: 24870509
Here it is. Please change the file extension into .xml
products.txt
0
 
LVL 14

Expert Comment

by:TanLiHao
ID: 24876542
I need the .xml file with the Arabic words, not English words so I can test. I do not know Arabic nor do I have Arabic fonts on my computer so I need you to provide me with both the font and the .xml with Arabic text.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question