Archive » August, 2006 «
Thursday, August 31st, 2006 | Author: dehash
A small example of embedding fonts in a textfield:
Actionscript:
-
package {
-
-
import flash.display.Sprite;
-
import flash.text.TextField;
-
import flash.text.TextFormat;
-
import flash.text.TextFieldAutoSize;
-
-
public class EmbedFontsExample extends Sprite {
-
-
[Embed(source="wingding.ttf", fontFamily="wingdingFont")]
-
private var MyFont:Class;
-
-
public function EmbedFontsExample() {
-
-
var tf:TextFormat = new TextFormat();
-
tf.font = "wingdingFont";
-
tf.size = 32;
-
-
var txt:TextField = new TextField();
-
txt.selectable = false;
-
txt.backgroundColor = 0xEEEEEE;
-
txt.embedFonts = true;
-
txt.autoSize = TextFieldAutoSize.LEFT;
-
txt.defaultTextFormat = tf;
-
txt.text = "Embed Fonts \nExample";
-
txt.x=50;
-
txt.y=50;
-
-
addChild(txt);
-
}
-
}
-
}
Category: Flash | Comments off
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:
-
<button label="ANT name after project" click="PluginCommand" image="54"
-
tag="Run;SaveAll;ant -buildfile nameafterproject.xml -Dproject.name=@PROJECTNAME"
-
shortcut="ShiftF11" />
// nameafterproject.xml
XML:
-
<?xml version="1.0"?>
-
<project name="set up project" default="nameafterproject" basedir="./">
-
<!-- include Bit-101 build.properties file -->
-
<property file="build.properties"/>
-
<target name="nameafterproject">
-
<!-- ensure project.name has a value-->
-
<fail unless="project.name" message="No project.name supplied"/>
-
<!-- check ${project.name}.as does not exist (don't want to overwrite by mistake)-->
-
<available file="${basedir}/${source.dir}/${project.name}.as"
-
property="project.name.as.file.present"/>
-
<fail if="project.name.as.file.present" message="${project.name}.as already exists"/>
-
<!-- copy App.as to ${project.name}.as -->
-
<copy file="${basedir}/${source.dir}/App.as"
-
tofile="${basedir}/${source.dir}/${project.name}.as"/>
-
<!-- change App to ${project.name} inside ${project.name}.as -->
-
<replaceregexp file="${basedir}/${source.dir}/${project.name}.as"
-
match="App" replace="${project.name}" byline="true"/>
-
<!-- change source.file & output.file values in build.properties -->
-
<replaceregexp file="${basedir}/build.properties"
-
match="^source.file=App.as$" replace="source.file=${project.name}.as"
-
byline="true"/>
-
<replaceregexp file="${basedir}/build.properties"
-
match="^output.file=App.swf$" replace="output.file=${project.name}.swf"
-
byline="true"/>
-
</target>
-
</project>
Category: Flash | Comments off
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 | Comments off
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:
-
<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:
-
xtrace([var1, var2]);
-
// which outputs the same as
-
xtrace(var1 + ", " + var2);
Category: Flash | 2 Comments
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:
-
package {
-
import flash.display.Sprite;
-
public class SVGEmbed extends Sprite {
-
[Embed(source="../assets/plainsvg1.svg")]
-
private var SimpleSVG:Class;
-
-
public function SVGEmbed() {
-
init();
-
}
-
private function init():void {
-
var mySVG:Sprite = new SimpleSVG();
-
mySVG.scaleX=0.5;
-
mySVG.scaleY=0.5;
-
addChild(mySVG);
-
}
-
}
-
}
Category: Code Examples, Flash, Flex SVG | 2 Comments
Monday, August 14th, 2006 | Author: dehash
Using the Penner easing equations directly:
more...
Category: Flash | Comments off
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
Wednesday, August 09th, 2006 | Author: dehash
I read that AS3 gives Flash the ability to encode binary data. For example that it is possible using ByteArray to encode a png from a BitmapData object.
I wanted to make a quick example to test this. So I grabbed an AS3 png encoder. Then I needed a dynamically changing BitmapData object so I grabbed a nice computeSpectrum example. For speed and convenience I also used Senocular's EasyButton and these three files (slightly modified) make up most of the code I used.
The resulting png data could be sent to the server and saved as a file but I chose to load the png data in the ByteArray into the current movie it using Loader.
There is a slight pause sometimes in the spectrum data when the button is pressed presumably because of the load and there may well be better ways to do it. But for a quick test it at least shows that it works in principle.
Here is a screenshot of the final movie and below is the swf. Just click the button once the audio has loaded and the png data will be encoded and output beneath the spectrumdata.
more...
Category: Flash | Comments off
Tuesday, August 08th, 2006 | Author: dehash
Below is a simple AS3 .swf file called BasicHelloWorld.swf
BasicHelloWorld.as code below compiled using EditPlus Ctrl+1
Actionscript:
-
package {
-
import flash.display.Sprite;
-
import flash.text.TextField;
-
public class BasicHelloWorld extends Sprite {
-
-
public function BasicHelloWorld () {
-
var mytextfield:TextField = new TextField();
-
mytextfield.text = "Basic Hello World";
-
addChild(mytextfield);
-
-
}
-
}
-
}
Category: Flash | Comments off
Sunday, August 06th, 2006 | Author: dehash
Category: Flash | Comments off
Thursday, August 03rd, 2006 | Author: dehash
The Flex 2 SDK is available for free download and can be used to create Flex and as3 Flash .swf movies and there is an excellent guide by senocular here which demonstrates using mxmlc.exe (included in the SDK download) on the command line to do this.
To use mxml.exe I am trying several editors to see which works best for me and EditPlus has some advantages including a toolbar called usertools which can be configured to call external applications for example to compile source code.
So I can compile a .mxml or .as file into a swf using a single toolbar button (or CTRL+1 keyboard shortcut) and view the compiler output (including any error messages) within the editor in the output window. To view the resulting swf in the stand alone flash 9 debug player (also included in the SDK download) with another single toolbar button (or CTRL+2 keyboard shortcut). This works if the swf is in the same location and has the same base name as the .as or .mxml file I am compiling.
The EditPlus file which controls this is c:\Program Files\EditPlus 2\tool.ini and mine is below. As you can see I have installed the SDK in c:\flex so the path to the compiler is C:\flex\bin\mxmlc.exe and to the Flash Player C:\flex\player\debug\SAFlashPlayer.exe which may not be identical to the setup on your system but can easily be changed using : Tools > Configure User Tools from within EditPlus.
more...
Category: Flash | Comments off