使用ActionScript 3自动调整大小的文本字段 [英] Auto size text field with Actionscript 3

查看:110
本文介绍了使用ActionScript 3自动调整大小的文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定是否可以,所以请在这里帮我一点忙:

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 和720dp x 720dp

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

它们都工作正常(不会超过735)

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

现在,我的问题是...假设对于1196 x 720,我有一个textField,一个textFormat和一个图例出现在屏幕顶部(作为标题):

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);

我(如果可能)如何根据屏幕分辨率自动调整textField的大小和格式以保持相同的比例?

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

推荐答案

尝试类似的方法.

    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;   
}

这篇关于使用ActionScript 3自动调整大小的文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆