45967

Auto size text field with Actionscript 3

Question:

I am not sure if this is possible, so, please, help me out a little bit over here:

I have an image loaded into the stage:

var miC:Loader = new Loader(); miC.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); miC.load(new URLRequest("coverph.jpg")); function onComplete(e:Event):void { miC.width = stage.stageWidth; miC.height = stage.stageHeight; miC.x = 0; miC.y = 0; addChild(miC); trace(miC.width, miC.height); }

And this way the image auto size itself to perfectly match the screen resolution (I have tried it with: (all in landscape)

960dp x 720dp 640dp x 480dp 470dp x 320dp 426dp x 320dp 1196dp x 720dp and 720dp x 720dp

They all worked fine (it won´t go over 735)

Now, my question is... let´s say that for the 1196 x 720 I have a textField, a textFormat and a legend that appears on the top of the screen (as a title):

var fmat:TextFormat = new TextFormat(); fmat.font = "Times New Roman"; fmat.size = 105; fmat.color = "0xFF0000"; var titulo:TextField = new TextField(); titulo.x = 145; titulo.y = 30; titulo.width = 1290; titulo.height = 122,10; titulo.defaultTextFormat = fmat; titulo.antiAliasType = AntiAliasType.ADVANCED; titulo.text = "THE TITLE OF WHAT IM DOING"; addChild(titulo);

How do I (if possible) auto size the textField and format to keep the same proportion according to the screen resolution?

Answer1:

Try something like this..

titulo.autoSize = "left"; titulo.text = "THE TITLE OF WHAT IM DOING"; var txt_holder:Sprite = new Sprite(); txt_holder.addChild(titulo); stage.addChild(txt_holder); stage.addEventListener(Event.RESIZE, onStageResize); function onStageResize(e:Event):void { txt_holder.width = stage.stageWidth * 0.8; // 80% width relative to stage txt_holder.scaleY = txt_holder.scaleX; // To keep aspectratio txt_holder.x = stage.stageWidth / 2; txt_holder.y = 10; }

Answer2:

With a few extra settings in your app you could calculate what the scaling factors should be for the x-axis and y-axis based on what the resolution is and then set the scalex and scaley properties of the TextField.

Reference: <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#propertySummary" rel="nofollow">http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#propertySummary</a>

Recommend

  • How to determine if a device is in portrait or landscape mode using CSS
  • How do I show an empty table in iReport 3.0.0?
  • Using iText to fill text field background
  • Android compass example does not seem to work in landscape mode
  • Auto Layout: Square Image View with equal width / height
  • Making ionic to open apps in landscape mode
  • Media Queries not responding on to Orientation Changes on iPhone 5
  • Allowing both landscape options and accelerometer with libgdx
  • Maintain Aspect Ratio in a Silverlight Image
  • Developing an universal android application (phone and tablet) - Defining Orientations
  • Pull all images from multiple directories and display them with PHP
  • MediaStore.ACTION_VIDEO_CAPTURE crashes camera app if device is portrait
  • How to convert multiple, different-sized PostScript files to a single PDF?
  • MPMoviePlayerController full screen orientation issue
  • iPhone: what is mean Landscape? [closed]
  • Truncate UILabel text before 5 character of string
  • Centering an image on screen using CSS - Random Screen/Image dimensions
  • Landscape iAd is showing the portrait graphic in iOS6?
  • Android: avoid calling onCreate() when back from another activity
  • What is the correct way to render_to_string in wicked pdf?
  • Distribute images evenly to columns in gallery
  • UIActionSheet orientation
  • How can I rotate a UIViewController to its supported interface orientation when navigating to it?
  • How to get phone heading for augmented reality?
  • I can't show LinearLayout at bottom to scroll view
  • Can I override some attribute of drawable shape?
  • Sticky Footer Below ListView in Android Layout
  • Generic/Unknown HTTP Error with response code 0 using UnityWebRequest
  • Query to find the duplicates between the name and number in table
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Eloquent update method change created_at timestamp
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Extracting HTML between tags
  • Change multiple background-images with jQuery
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Android screen density dpi vs ppi
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Change an a tag attribute in JavaScript based on screen width