การเก็บค่า Font size ใน MC มาแสดงต้องทำไงคะ

เริ่มโพสต์โดย sarina, 15 ก.ค. 2008, 11:20 น.

0 สมาชิก และ 1 บุคคลทั่วไป กำลังเปิดอ่านโพสต์นี้

sarina

http://img2.f0nt.com/flash/dc24ddb8c28a6874f22fda7758adb3f1.swf
เมื่อขยาย scale ของ MC แล้ว   มันสามารถเก็บค่าขนาดของ Font size ยังไงคะ
ซึ่งเมื่อมีการขยาย scale ของ MC จะมี textbox แสดงขนาด ของ font ว่าตอนนี้ขนาดกี่พ้อยต์แล้ว
ช่วยแนะนำหน่อยนะคะ....

ej_sing

อันนี้ไม่แน่ใจครับ
เพราะ ของน้องเวลาขยายมันจะขยายด้วย _xscale _yscale (ใช่ไหม)
ไม่ได้ขยายจากขนาดฟ้อนต์

อาจต้องใช้วิธีเทียบขนาดเอาว่า font size ขนาดนี้เท่ากับ  _xscale _yscale เท่าไร


เดาเอา

sarina

#2
ค่ะพี่ ej_sing
:05: แล้วถ้าจะทำการเทียบค่าต้องทำยังไงบ้างอ่ะคะ

function showFontSelect(obj){
    myTxtFormat.font = myCombo_cb.getItemAt(myCombo_cb.selectedIndex).data;
    buf_obj.obj_area.obj_txt.display_txt.setTextFormat(myTxtFormat);
    updateScale(buf_obj);
}

function lockColor(){
    fmt = buf_obj.obj_area.obj_txt.display_txt.getTextFormat();
    codeColor = "0x" + fmt.color.toString(16);
    buf_obj.obj_area.obj_txt.display_txt.textColor = codeColor;
}

function change_selected(newsel:Number){
   if(newsel != _root.selVal){
      if (_root.selVal != 0) {
         var old_mc:MovieClip = eval("obj_"+_root.selVal);
         old_mc.obj_del._visible = false;
         old_mc.obj_rotate._visible = false;
         old_mc.obj_scale._visible = false;
         old_mc.obj_area.obj_stage._alpha = 0;
      }
      _root.selVal = newsel;
      if(newsel != 0){
         var new_mc:MovieClip = eval("obj_"+_root.selVal);
         new_mc.swapDepths(this.getNextHighestDepth());
         new_mc.obj_del._visible = true;
         new_mc.obj_rotate._visible = true;
         new_mc.obj_scale._visible = true;
         new_mc.obj_area.obj_stage._alpha = 100;
         var input_text:TextField = eval("txt_"+_root.selVal);
         Selection.setFocus(input_text);
         Selection.setSelection(input_text.text.length,input_text.text.length);
      }
   }
}

function updateScale(mc:MovieClip) {
   // rescale obj_area.obj_stage
   mc.obj_area.obj_stage._width = mc.obj_area.obj_txt._width;
   mc.obj_area.obj_stage._height = mc.obj_area.obj_txt._height;
   // reset position obj_area.obj_stage
   var obj_rect_obj:Object = mc.obj_area.obj_txt.getBounds(mc.obj_area);
   mc.obj_area.obj_stage._x = obj_rect_obj.xMin;
   mc.obj_area.obj_stage._y = obj_rect_obj.yMin;
   // rescale obj_area
   if(mc.obj_area._width > obj_main_stage._width){
      mc.obj_area._width = obj_main_stage._width
      mc.obj_area._yscale = mc.obj_area._xscale;
   }
   if (mc.obj_area._height > obj_main_stage._height) {
      mc.obj_area._height = obj_main_stage._height;
      mc.obj_area._xscale = mc.obj_area._yscale;
   }
   // reset mc._x and mc._y
   var rect_obj:Object = mc.obj_area.getBounds(mc);
   var min_x:Number = rect_obj.xMin;
   var min_y:Number = rect_obj.yMin;
   var max_x:Number = rect_obj.xMax;
   var max_y:Number = rect_obj.yMax;
   var main_rect_obj:Object = mc.obj_area.getBounds(_root);
   var main_min_x:Number = main_rect_obj.xMin;
   var main_min_y:Number = main_rect_obj.yMin;
   var main_max_x:Number = main_rect_obj.xMax;
   var main_max_y:Number = main_rect_obj.yMax;
   if (main_min_x < obj_main_stage._x) {
      mc._x = obj_main_stage._x - min_x;
   }
   if (main_min_y < obj_main_stage._y) {
      mc._y = obj_main_stage._y - min_y;
   }
   if (main_max_x > obj_main_stage._x + obj_main_stage._width) {
      mc._x = obj_main_stage._x + obj_main_stage._width - mc.obj_area._width - min_x;
   }
   if (main_max_y > obj_main_stage._y + obj_main_stage._height) {
      mc._y = obj_main_stage._y + obj_main_stage._height - mc.obj_area._height - min_y;
   }
   // set position obj_del, obj_rotate, obj_scale
      mc.obj_del._x = min_x;
      mc.obj_del._y = min_y;
      mc.obj_rotate._x = max_x;
      mc.obj_rotate._y = min_y;
      mc.obj_scale._x = max_x;
      mc.obj_scale._y = max_y;
 
}

_root.selVal = 1;
obj_main_stage.onRelease = _root.onRelease = function ()
{
    change_selected(0);
};

var myFontLabel = ["AngsanaUPC", "Arial", "Arial Black", "AvantGarde Bk BT", "AvantGarde Md BT"];
var listContent = ["AngsanaUPC", "Arial", "Arial_Black", "AvantGarde Bk BT", "AvantGarde Md BT"];
var myCombo_cb;
var myTxtFormat = new TextFormat();

for (var i = 0;i <= 4;i++)
{
    myCombo_cb.addItem(myFontLabel[i], listContent[i], listContent[i]);
}

myCombo_cb.addEventListener("change", showFontSelect);
myTxtFormat.font = listContent[0];
buf_obj.obj_area.obj_txt.display_txt.setTextFormat(myTxtFormat);


myCombo_cb.addEventListener ("load", setCBListFonts);
myCombo_cb.addEventListener ("scroll", setCBListFonts);

function setCBListFonts ()
{
for (var i in myCombo_cb.dropdown.listContent)
{
var _tf:TextFormat = myCombo_cb.dropdown.listContent[i].cell.getTextFormat ();
_tf.font = myCombo_cb.dropdown.listContent[i].cell.text;
myCombo_cb.dropdown.listContent[i].cell.setTextFormat (_tf);
}
}

//*************

var buf_obj;
var my_fmt = new TextFormat();
var pickerListener = new Object();
pickerListener.change = function (cl)
{
    codeColor = "0x" + cl.getRGB();
    my_fmt.color = codeColor;
    buf_obj.obj_area.obj_txt.display_txt.setTextFormat(my_fmt);
    lockColor();
};
clp.addListener(pickerListener);
lockColor();
clp.color = codeColor;

for (var i = 1;i <= 3;i++)
{
    var input_text = eval("txt_" + i);
    input_text.thisval = i;
    input_text.onSetFocus = function ()
    {
        buf_obj = eval("obj_" + this.thisval);
        change_selected(buf_obj.thisval);
lockColor();
    clp.color = codeColor;
    };
    input_text.onChanged = function ()
    {
        buf_obj = eval("obj_" + this.thisval);
        fmt = buf_obj.obj_area.obj_txt.display_txt.getTextFormat();
        _root.selVar = this.thisval;
        change_selected(buf_obj.thisval);
        if (this.text.length > 0)
        {
            buf_obj._visible = true;
        }
        else
        {
            buf_obj._visible = false;
        }
        buf_obj.obj_area.obj_txt.display_txt.text = this.text;
        buf_obj.obj_area.obj_txt.display_txt.setTextFormat(fmt);
        updateScale(buf_obj);
lockColor();
clp.color = codeColor;
     
   };
    var obj = eval("obj_" + i);
    obj.thisval = i;
    obj.obj_area.obj_txt.display_txt.autoSize = true;

    updateScale(obj);
    obj._visible = false;

//event delete button
    obj.obj_del.onRelease = function ()
    {
        this._parent._visible = false;
        this._parent.obj_area._xscale = 100;
        this._parent.obj_area._yscale = 100;
        this._parent.obj_area.obj_txt._rotation = 0;
        var buf_input_text = eval("txt_" + this._parent.thisval);
        buf_input_text.text = "";
    } ;
//event scale button
obj.obj_scale.onPress = function() {
//start_scale
this.startWidth = this._parent.obj_area._width;
this.startMouseX = _root._xmouse;
this.onEnterFrame = function() {
var new_width:Number = this.startWidth+_root._xmouse-this.startMouseX;
if (new_width > this._parent.obj_area._width && new_width > obj_main_stage._width) {
this._parent.obj_area._width = obj_main_stage._width;
} else {
this._parent.obj_area._width = new_width;
}
this._parent.obj_area._yscale = this._parent.obj_area._xscale;
updateScale(this._parent);
 
};
};
obj.obj_scale.onRelease = obj.obj_scale.onReleaseOutside=function () {
delete this.onEnterFrame;
};

//event rotate button
obj.obj_rotate.onPress = function() {
//start_scale
this.startRotate = this._parent.obj_area.obj_txt._rotation;
this.startMouseX = this._parent._x;
this.startMouseY = _root._ymouse;
this.onEnterFrame = function() {
//this._parent.obj_area.obj_txt._rotation++;
var new_x:Number = _root._xmouse - this.startMouseX;
var new_y:Number = _root._ymouse - this.startMouseY;
this._parent.obj_area.obj_txt._rotation = this.startRotate + (Math.atan2(new_y, new_x)*90);
updateScale(this._parent);
};
};
obj.obj_rotate.onRelease = obj.obj_rotate.onReleaseOutside=function () {
delete this.onEnterFrame;
};
//event move object
obj.obj_area.onPress = function() {
      //start_scale
      var buf_mc:MovieClip = this._parent;
      change_selected(buf_mc.thisval);
      this.startX = buf_mc._x;
      this.startY = buf_mc._y;
      this.startMouseX = _root._xmouse;
      this.startMouseY = _root._ymouse;
      this.onEnterFrame = function() {
         this._parent._x = this.startX+_root._xmouse-this.startMouseX;
         this._parent._y = this.startY+_root._ymouse-this.startMouseY;
         updateScale(this._parent);
      };
   };
   obj.obj_area.onRelease = obj.obj_area.onReleaseOutside=function () {
   delete this.onEnterFrame;
   };
}

ej_sing

 :44: รอท่านอื่นๆนะ ไม่รู้ว่าจะเทียบแบบไหนเหมือนกันจ้า

ยุนเอ



ยังงงอยู่ครับว่าขยายขนาด textbox แล้วไปโดนตัวอักษรได้ยังไง
เราจะต้องการอะไรมากมายไปกว่า อะไรมากมาย

sarina

#5
ขยายขนาดของ MC ค่ะ
http://img2.f0nt.com/flash/dc24ddb8c28a6874f22fda7758adb3f1.swf
โดยเมื่อขยาย scale ของ MC แล้ว   มันสามารถเก็บค่าขนาดของ Font size
และแสดงขนาด ของ font ว่าตอนนี้ขนาดกี่พ้อยต์แล้วยังไงคะ

function showFontSelect(obj){
    myTxtFormat.font = myCombo_cb.getItemAt(myCombo_cb.selectedIndex).data;
    buf_obj.obj_area.obj_txt.display_txt.setTextFormat(myTxtFormat);
    updateScale(buf_obj);
}

function lockColor(){
    fmt = buf_obj.obj_area.obj_txt.display_txt.getTextFormat();
    codeColor = "0x" + fmt.color.toString(16);
    buf_obj.obj_area.obj_txt.display_txt.textColor = codeColor;
}

function change_selected(newsel:Number){
   if(newsel != _root.selVal){
      if (_root.selVal != 0) {
         var old_mc:MovieClip = eval("obj_"+_root.selVal);
         old_mc.obj_del._visible = false;
         old_mc.obj_rotate._visible = false;
         old_mc.obj_scale._visible = false;
         old_mc.obj_area.obj_stage._alpha = 0;
      }
      _root.selVal = newsel;
      if(newsel != 0){
         var new_mc:MovieClip = eval("obj_"+_root.selVal);
         new_mc.swapDepths(this.getNextHighestDepth());
         new_mc.obj_del._visible = true;
         new_mc.obj_rotate._visible = true;
         new_mc.obj_scale._visible = true;
         new_mc.obj_area.obj_stage._alpha = 100;
         var input_text:TextField = eval("txt_"+_root.selVal);
         Selection.setFocus(input_text);
         Selection.setSelection(input_text.text.length,input_text.text.length);
      }
   }
}

function updateScale(mc:MovieClip) {
   // rescale obj_area.obj_stage
   mc.obj_area.obj_stage._width = mc.obj_area.obj_txt._width;
   mc.obj_area.obj_stage._height = mc.obj_area.obj_txt._height;
   // reset position obj_area.obj_stage
   var obj_rect_obj:Object = mc.obj_area.obj_txt.getBounds(mc.obj_area);
   mc.obj_area.obj_stage._x = obj_rect_obj.xMin;
   mc.obj_area.obj_stage._y = obj_rect_obj.yMin;
   // rescale obj_area
   if(mc.obj_area._width > obj_main_stage._width){
      mc.obj_area._width = obj_main_stage._width
      mc.obj_area._yscale = mc.obj_area._xscale;
   }
   if (mc.obj_area._height > obj_main_stage._height) {
      mc.obj_area._height = obj_main_stage._height;
      mc.obj_area._xscale = mc.obj_area._yscale;
   }
   // reset mc._x and mc._y
   var rect_obj:Object = mc.obj_area.getBounds(mc);
   var min_x:Number = rect_obj.xMin;
   var min_y:Number = rect_obj.yMin;
   var max_x:Number = rect_obj.xMax;
   var max_y:Number = rect_obj.yMax;
   var main_rect_obj:Object = mc.obj_area.getBounds(_root);
   var main_min_x:Number = main_rect_obj.xMin;
   var main_min_y:Number = main_rect_obj.yMin;
   var main_max_x:Number = main_rect_obj.xMax;
   var main_max_y:Number = main_rect_obj.yMax;
   if (main_min_x < obj_main_stage._x) {
      mc._x = obj_main_stage._x - min_x;
   }
   if (main_min_y < obj_main_stage._y) {
      mc._y = obj_main_stage._y - min_y;
   }
   if (main_max_x > obj_main_stage._x + obj_main_stage._width) {
      mc._x = obj_main_stage._x + obj_main_stage._width - mc.obj_area._width - min_x;
   }
   if (main_max_y > obj_main_stage._y + obj_main_stage._height) {
      mc._y = obj_main_stage._y + obj_main_stage._height - mc.obj_area._height - min_y;
   }
   // set position obj_del, obj_rotate, obj_scale
      mc.obj_del._x = min_x;
      mc.obj_del._y = min_y;
      mc.obj_rotate._x = max_x;
      mc.obj_rotate._y = min_y;
      mc.obj_scale._x = max_x;
      mc.obj_scale._y = max_y;
 
}

_root.selVal = 1;
obj_main_stage.onRelease = _root.onRelease = function ()
{
    change_selected(0);
};

var myFontLabel = ["AngsanaUPC", "Arial", "Arial Black", "AvantGarde Bk BT", "AvantGarde Md BT"];
var listContent = ["AngsanaUPC", "Arial", "Arial_Black", "AvantGarde Bk BT", "AvantGarde Md BT"];
var myCombo_cb;
var myTxtFormat = new TextFormat();

for (var i = 0;i <= 4;i++)
{
    myCombo_cb.addItem(myFontLabel[i], listContent[i], listContent[i]);
}

myCombo_cb.addEventListener("change", showFontSelect);
myTxtFormat.font = listContent[0];
buf_obj.obj_area.obj_txt.display_txt.setTextFormat(myTxtFormat);


myCombo_cb.addEventListener ("load", setCBListFonts);
myCombo_cb.addEventListener ("scroll", setCBListFonts);

function setCBListFonts ()
{
for (var i in myCombo_cb.dropdown.listContent)
{
var _tf:TextFormat = myCombo_cb.dropdown.listContent[i].cell.getTextFormat ();
_tf.font = myCombo_cb.dropdown.listContent[i].cell.text;
myCombo_cb.dropdown.listContent[i].cell.setTextFormat (_tf);
}
}

//*************

var buf_obj;
var my_fmt = new TextFormat();
var pickerListener = new Object();
pickerListener.change = function (cl)
{
    codeColor = "0x" + cl.getRGB();
    my_fmt.color = codeColor;
    buf_obj.obj_area.obj_txt.display_txt.setTextFormat(my_fmt);
    lockColor();
};
clp.addListener(pickerListener);
lockColor();
clp.color = codeColor;

for (var i = 1;i <= 3;i++)
{
    var input_text = eval("txt_" + i);
    input_text.thisval = i;
    input_text.onSetFocus = function ()
    {
        buf_obj = eval("obj_" + this.thisval);
        change_selected(buf_obj.thisval);
lockColor();
    clp.color = codeColor;
    };
    input_text.onChanged = function ()
    {
        buf_obj = eval("obj_" + this.thisval);
        fmt = buf_obj.obj_area.obj_txt.display_txt.getTextFormat();
        _root.selVar = this.thisval;
        change_selected(buf_obj.thisval);
        if (this.text.length > 0)
        {
            buf_obj._visible = true;
        }
        else
        {
            buf_obj._visible = false;
        }
        buf_obj.obj_area.obj_txt.display_txt.text = this.text;
        buf_obj.obj_area.obj_txt.display_txt.setTextFormat(fmt);
        updateScale(buf_obj);
lockColor();
clp.color = codeColor;
     
   };
    var obj = eval("obj_" + i);
    obj.thisval = i;
    obj.obj_area.obj_txt.display_txt.autoSize = true;

    updateScale(obj);
    obj._visible = false;

//event delete button
    obj.obj_del.onRelease = function ()
    {
        this._parent._visible = false;
        this._parent.obj_area._xscale = 100;
        this._parent.obj_area._yscale = 100;
        this._parent.obj_area.obj_txt._rotation = 0;
        var buf_input_text = eval("txt_" + this._parent.thisval);
        buf_input_text.text = "";
    } ;
//event scale button
obj.obj_scale.onPress = function() {
//start_scale
this.startWidth = this._parent.obj_area._width;
this.startMouseX = _root._xmouse;
this.onEnterFrame = function() {
var new_width:Number = this.startWidth+_root._xmouse-this.startMouseX;
if (new_width > this._parent.obj_area._width && new_width > obj_main_stage._width) {
this._parent.obj_area._width = obj_main_stage._width;
} else {
this._parent.obj_area._width = new_width;
}
this._parent.obj_area._yscale = this._parent.obj_area._xscale;
updateScale(this._parent);
 
};
};
obj.obj_scale.onRelease = obj.obj_scale.onReleaseOutside=function () {
delete this.onEnterFrame;
};

//event rotate button
obj.obj_rotate.onPress = function() {
//start_scale
this.startRotate = this._parent.obj_area.obj_txt._rotation;
this.startMouseX = this._parent._x;
this.startMouseY = _root._ymouse;
this.onEnterFrame = function() {
//this._parent.obj_area.obj_txt._rotation++;
var new_x:Number = _root._xmouse - this.startMouseX;
var new_y:Number = _root._ymouse - this.startMouseY;
this._parent.obj_area.obj_txt._rotation = this.startRotate + (Math.atan2(new_y, new_x)*90);
updateScale(this._parent);
};
};
obj.obj_rotate.onRelease = obj.obj_rotate.onReleaseOutside=function () {
delete this.onEnterFrame;
};
//event move object
obj.obj_area.onPress = function() {
      //start_scale
      var buf_mc:MovieClip = this._parent;
      change_selected(buf_mc.thisval);
      this.startX = buf_mc._x;
      this.startY = buf_mc._y;
      this.startMouseX = _root._xmouse;
      this.startMouseY = _root._ymouse;
      this.onEnterFrame = function() {
         this._parent._x = this.startX+_root._xmouse-this.startMouseX;
         this._parent._y = this.startY+_root._ymouse-this.startMouseY;
         updateScale(this._parent);
      };
   };
   obj.obj_area.onRelease = obj.obj_area.onReleaseOutside=function () {
   delete this.onEnterFrame;
   };
}


ช่วยแนะนำหน่อยนะคะ....



ej_sing

อืมม จริงๆต้องดูว่า
จะเอาขนาดอะไรแน่

เพราะ

fontsize มันเท่าเดิม แต่มันขยายที่ xscale yscale ของ mc นั้นๆ ฟ้อนต์เลยขยายไปด้วย

อืมมมม

สรุปแล้วไม่ต้องมีขยาย xscale yscale
แต่เรามาขยายที่ fontsize เอาดีกว่าไหมครับ ขนาดคงที่ดีด้วย

หรือไงดี

sarina

อ้างคำพูดจาก: ej_sing เมื่อ 15 ก.ค. 2008, 22:39 น.
อืมม จริงๆต้องดูว่า
จะเอาขนาดอะไรแน่

เพราะ

fontsize มันเท่าเดิม แต่มันขยายที่ xscale yscale ของ mc นั้นๆ ฟ้อนต์เลยขยายไปด้วย

อืมมมม

สรุปแล้วไม่ต้องมีขยาย xscale yscale
แต่เรามาขยายที่ fontsize เอาดีกว่าไหมครับ ขนาดคงที่ดีด้วย

หรือไงดี

**แล้วถ้าแก้เป็นขยาย  fontsize ต้องแก้โค๊ดหมดเลยป่าวค่ะ :05:
แล้วมันต้องเขียนยังไงหรอ  กลัวจังเลยค่ะ  ช่วยหน่อยนะคะ


ej_sing

ถ้าแก้ที่ fontsize ก็อาจจะต้องตัดส่วนที่ลากแล้วขยายทิ้งซะ ง่ายที่สุด

หรือไม่ก็ทำลากแล้วขยายที่ fontsize เอา ไม่ต้องขยาย xscale yscale (ท่าทางอันนี้ยุ่งยากหน่อย)


ลองหาดูใน help นะครับ เกี่ยวกับ fontSize น่ะ แล้วค่อยมาถามอีกที

sarina

 :01: ถ้าให้    font size ปัจจุบัน = font size ตอนแรก * mc._xscale/100
มันจะพอทำได้ป่าวคะ   แต่ถ้าเขียนจิงๆมันต้องเขียนแบบไหนกันคะ :28:

ej_sing

อ้างคำพูดจาก: ej_sing เมื่อ 16 ก.ค. 2008, 01:46 น.
ลองหาดูใน help นะครับ เกี่ยวกับ fontSize น่ะ แล้วค่อยมาถามอีกที

ลองดูสิครับ


poloh

20 pt ขนาดมันเป็น 2 เท่าของ 10 pt จริงหรือเปล่าครับ
ถ้าจริง จะใช้สูตรคำนวณเอา ก็เต็มที่เลยครับ

แต่ว่า มันจำเป็นจริงหรือไม่ที่จะต้องแสดงขนาดตัวอักษร
เป็น pt แสดงเป็น % แทนจะได้ไหม
หรือไม่แสดงเลยจะเป็นไรหรือเปล่า?
หรือจะแสดงเป็นขนาดความกว้าง ความสูงของตัวปัจจุบันแทนดีกว่าไหม

ผมไม่ใช่คนออกแบบ หรือคนทำงานคงพูดอะไรได้ไม่มาก
แต่ถ้าอะไรที่สงสัย แล้วพอทำได้ ก็ทำไปเลยครับ :12:
ไม่ก็ลองเสนอทางอื่นที่ใกล้เคียงให้ลูกค้าดูก็ดีครับ ดีกว่าติดอยู่แบบนี้

พยายามต่อไปละกันครับ :12:
ก่อสร้างกับทำลาย เหมือนที่ลงมือ ต่างที่การกระทำ

sarina

 :33: ขอบคุณมากค่ะ

ตอนนี้ทำได้แล้วค่ะ
โดยใช้สูตรนี้ค่ะ  font size ปัจจุบัน = font size ตอนแรก * mc._xscale/100
จนมาเป็น
_root.txt =((16 * (this._parent.obj_area._xscale))/100);

เพราะขนาดฟ้อนที่กำหนดให้กับ dynamic text ในตอนแรก = 16 (มันเลยดีฟ้อลให้)
แล้วเอา 16 มาใช้ในสูตรเลย

ej_sing


SMF 2.1.7 © 2026, Simple Machines