วิธีทำให้ TextField ใน Flash CS5 มี Font ตัวหนา เมื่อถูกแก้ไขโดย Flex by Ziah
Sep0
โดยปกติแล้วถ้าเราตั้ง TextField ใน Flash ให้มีตัวหนาแล้ว มันก็จะคงฟอนท์ตัวหนาไว้ตลอด แต่เมื่อเรามาแก้ไขตัวหนังสือของมันด้วย Flex แล้วมันจะทำให้ฟอนท์ของ TextField ดังกล่าวกลายเป็นตัวธรรมดาไปเฉยๆ วันนี้มีวิธีแก้มาฝากกันครับ
เมื่อเรานำ Flash ด้านบนเข้าไปใช้ใน Flex แล้วสั่งให้มีการแก้ไขข้อความใน TextField
ผลลัพธ์คือตัวอักษรจะไม่ติดตัวหนาแล้ว
txt_name.text = “Cybermon”;
txt_skill.text = “Destroy itself after attack”;
วิธีแก้ไขก็ไม่ยากเลยครับ หลังจากที่เราใส่ค่าใหม่แล้ว เราต้องทำการเรียก setTextFormat เพื่อตั้งค่าให้เป็นตัวหนาอีกรอบครับ
ตัวอย่าง
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.bold = true;
myTextField.setTextFormat(myTextFormat);
หรือเราจะเขียนย่อๆแบบนี้ก็ได้ครับถ้าเรารู้ว่ามันรับ Parameter ยังไงบ้างแล้ว (เพิ่มเติม) ซึ่งจะทำให้ได้โค้ดดังนี้
txt_name.text = “Cybermon”;
txt_skill.text = “Destroy itself after attack”;
txt_name.setTextFormat(new TextFormat(null,null,null,true));
txt_skill.setTextFormat(new TextFormat(null,null,null,true));
เท่านี้เราก็จะได้ผลลัพธ์เป็นตัวหนาตามปกติแล้วล่ะครับ
Starling Asset Manager by arthit_game
Feb0
package
{
import flash.display.Bitmap;
import flash.utils.Dictionary;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
public class Assets
{
[Embed(source="../system/Blackground.jpg")]
public static const Blackground:Class;
[Embed(source="../assets/audio/sound1.mp3")]
public static const sound1:Class;
private static var gameTextureAtlas:TextureAtlas;
[Embed(source="../assets/textures/atlas.png")]
public static const atlasTexture:Class;
[Embed(source="../assets/textures/atlas.xml", mimeType="application/octet-stream")]
public static const atlasXML:Class;
public static function getAtlas():TextureAtlas
{
if (gameTextureAtlas == null)
{
var texture:Texture = getTexture("atlasTexture");
var xml:XML = XML(new atlasXML());
gameTextureAtlas = new TextureAtlas(texture, xml);
}
return gameTextureAtlas;
}
private static var gameTextures:Dictionary = new Dictionary();
public static function getTexture(name:String):Texture
{
if (gameTextures[name] == undefined)
{
var bitmap:Bitmap = new Assets[name]();
gameTextures[name] = Texture.fromBitmap(bitmap);
}
return gameTextures[name];
}
}
}
import starling.utils.AssetManager;
import starling.display.Sprite;
import starling.display.Image;
import flash.media.Sound;
private static var sAssets:AssetManager;
public function Main() extends Sprite
{
sAssets = new AssetManager();
//Add Texture
sAssets.addTexture("nameBlackground",Assets.getTexture("Blackground"));
//Add Atlas
sAssets.addTextureAtlas("atlas1",Assets.getAtlas());
//Add Sound
sAssets.addSound("sound1",new Assets.sound1() as Sound);
}
public function exampleUse():void
{
//Texture
var img:Image = new Image( assets.getTexture("nameBlackground"));
this.addChild(img);
//Atlast
var mc:MovieClip = new MovieClip( assets.getTextureAtlas("atlas1").getTextures("heroAttack"),12);
Starling.juggler.add(mc);//For sprite to play animation
this.addChild(mc);
//Sound
var s1:Sound = assets.getSound("sound1");
s1.play(0,1);
}
public static function get assets():AssetManager { return sAssets; }
การส่งค่าจากแฟลชให้แสดงที่ console ในเว็บเบราเซอร์ต่างๆ by Ziah
Sep0
โดยปกติแล้วเราชาว Flash โปรแกรมเมอร์เวลาต้องการจะเช็คค่าที่ตำแหน่งต่างๆของโค้ดของเรา เราก็มักจะใช้ trace(“//string”); เพื่อเช็คค่าต่างๆขณะที่รันเทสแอปพลิเคชั่นของเรา แต่ในบางทีแล้วเราต้องการที่จะดักค่าที่เราต้องการทดสอบกับข้อมูลจริง ซึ่งต้องเป็นตัวที่ publish ไปรันบนแอปพลิเคชั่นจริงๆแล้วเราจึงไม่สามารถดู trace ที่เราเขียนขึ้นมาได้ เราจึงต้องมีการใช้วิธีต่างกันไป โดยวิธีที่จะนำมาเสนอในวันนี้จะเป็นดังนี้ครับ
เราจะทำการเรียกฟังก์ชั่น console.log ของ javascript ซึ่งจะแสดงค่าที่เราใส่ไว้ใน console ของ Developer Tools ที่มีใน Web Browser ในสมัยนี้ ซึ่งต่างๆกันไป
วิธีการเรียก console.log ก็จะมีหน้าตาดังนี้
ExternalInterface.call("console.log",[{
'test':"call me maybe"
}]);
จากการใช้ ฟังก์ชั่น ExternalInterface.call ซึ่งรับค่าสองตัว คือ ชื่อฟังก์ชั่น JS ที่จะเรียกและ ค่า Argument ที่จะส่งไปในฟังก์ชั่นนั้น ทำให้เราสามารถเรียกฟังก์ชั่น console.log ได้โดยใส่ค่าที่ต้องแสดงหรือตัวแปรที่ต้องการทราบค่า (นอกจากนั้นเรายังสามารถใส่ Object ทั้งก้อนเพื่อดูค่าด้านในได้เลยซึ่ง trace ทำไม่ได้)
ซึ่งจะทำให้เราเห็นค่าดังนี้