Home

Archive » August, 2006 «

AS3 Embedding Fonts

Thursday, August 31st, 2006 | Author: dehash

A small example of embedding fonts in a textfield:

Actionscript:
  1. package {
  2.  
  3. import flash.display.Sprite;
  4. import flash.text.TextField;
  5. import flash.text.TextFormat;
  6. import flash.text.TextFieldAutoSize;
  7.  
  8.    public class EmbedFontsExample extends Sprite {
  9.    
  10.       [Embed(source="wingding.ttf", fontFamily="wingdingFont")]
  11.       private var MyFont:Class;
  12.       
  13.       public function EmbedFontsExample() {
  14.                    
  15.           var tf:TextFormat = new TextFormat();
  16.           tf.font = "wingdingFont";
  17.           tf.size = 32;  
  18.           
  19.           var txt:TextField = new TextField();
  20.           txt.selectable = false;
  21.           txt.backgroundColor = 0xEEEEEE;
  22.           txt.embedFonts = true;
  23.           txt.autoSize = TextFieldAutoSize.LEFT;
  24.           txt.defaultTextFormat = tf;
  25.           txt.text = "Embed Fonts \nExample";
  26.           txt.x=50;
  27.           txt.y=50;   
  28.           
  29.           addChild(txt);
  30.        }
  31.     }
  32. }

Category: Flash | Leave a Comment

A little more FlashDevelop and Ant

Friday, August 25th, 2006 | Author: dehash

nameafterproject.xml is an ant build file that automates a few changes I was making each time to the Bit-101 FlashDevelop AS3 Project template. After running it with Ant (immediately after making a new AS3 Project) my project name, main class, & target swf all have the same base name which saves me some typing as I prefer it that way. It needs working on a little but it does the job fine for now. I have put it in \FlashDevelop\Data\ProjectTemplates\05 AS3 Project\nameafterproject.xml and to run it add this line in ToolBar.xml

XML:
  1. <button label="ANT name after project" click="PluginCommand" image="54" 
  2. tag="Run;SaveAll;ant -buildfile nameafterproject.xml -Dproject.name=@PROJECTNAME"
  3. shortcut="ShiftF11" />

// nameafterproject.xml

XML:
  1. <?xml version="1.0"?>
  2. <project name="set up project" default="nameafterproject" basedir="./">
  3. <!-- include Bit-101 build.properties file -->
  4. <property file="build.properties"/>
  5. <target name="nameafterproject">
  6. <!-- ensure project.name has a value-->
  7. <fail unless="project.name" message="No project.name supplied"/>
  8. <!-- check ${project.name}.as does not exist (don't want to overwrite by mistake)-->
  9. <available file="${basedir}/${source.dir}/${project.name}.as"
  10. property="project.name.as.file.present"/>
  11. <fail if="project.name.as.file.present" message="${project.name}.as already exists"/>
  12. <!-- copy App.as to ${project.name}.as -->
  13. <copy file="${basedir}/${source.dir}/App.as"
  14. tofile="${basedir}/${source.dir}/${project.name}.as"/>
  15. <!-- change App to ${project.name} inside ${project.name}.as -->
  16. <replaceregexp file="${basedir}/${source.dir}/${project.name}.as"
  17. match="App" replace="${project.name}" byline="true"/>
  18. <!-- change source.file & output.file values in build.properties -->
  19. <replaceregexp file="${basedir}/build.properties"
  20. match="^source.file=App.as$" replace="source.file=${project.name}.as"
  21. byline="true"/>     
  22. <replaceregexp file="${basedir}/build.properties"
  23. match="^output.file=App.swf$" replace="output.file=${project.name}.swf"
  24. byline="true"/>
  25. </target>
  26. </project>

Category: Flash | Leave a Comment

Nice code syntax highlighting

Tuesday, August 22nd, 2006 | Author: dehash

Displaying code was being a bit of a pain and I thought I would have to devote a lot of time to making some cool and complex system to make pasting code here easy. But I just got the iG:Syntax Hiliter which I found out about here and after five minutes it is working very well and I am very happy with that. Seems a good solution :)

Category: Flash | Leave a Comment

Using FlashDevelop

Sunday, August 20th, 2006 | Author: dehash

In addition to the instructions here I have added an entry to ToolBar.xml so that I can display the swf in the standalone Flash player. It calls ant on the build.xml file with the target "launchstandalone" :

XML:
  1. <button label="StandAlone" click="PluginCommand" image="54" tag="Run;SaveAll;ant launchstandalone" shortcut="F11" />

Also added xtrace.as to \ProjectTemplates\05 AS3 Project\src\ and it can be used without import in all projects

Also xtrace can take an array as an argument for example:

Actionscript:
  1. xtrace([var1, var2]);
  2. // which outputs the same as
  3. xtrace(var1 + ", " + var2);

Category: Flash | 2 Comments

Embedding a SVG file

Thursday, August 17th, 2006 | Author: dehash

SVG file drawn using Inkscape and embedded in swf at compile time. The box at bottom left had a radial gradient fill in the svg that does not appear in the swf.

SVGEmbed.as code below compiled using FlashDevelop and a Bit-101 template

Actionscript:
  1. package {
  2. import flash.display.Sprite;
  3. public class SVGEmbed extends Sprite {
  4. [Embed(source="../assets/plainsvg1.svg")]
  5. private var SimpleSVG:Class;
  6.  
  7. public function SVGEmbed() {
  8. init();
  9. }
  10. private function init():void {
  11. var mySVG:Sprite = new SimpleSVG();
  12. mySVG.scaleX=0.5;
  13. mySVG.scaleY=0.5;
  14. addChild(mySVG);
  15. }
  16. }
  17. }

Category: Code Examples, Flash, Flex SVG | 2 Comments

AS3 Easing

Monday, August 14th, 2006 | Author: dehash

Using the Penner easing equations directly:

more...

Category: Flash | Leave a Comment

FlashDevelop AS3 tutorial

Thursday, August 10th, 2006 | Author: dehash

BIT-101 has written a great tutorial showing howto setup FlashDevelop for AS3 work.
Works right out of the box and will probably become my editor of choice. Plus some nice code templates too.

Category: Flash | 2 Comments