AS3: Fabrication templates/snippets for FlashDevelop

I’d like to share a few snippets and templates that are essential in working with the Fabrication framework in Flash Develop:


SNIPPETS:

process - reflexive notification via namespaces
proxy - proxy injection
reactToClick - reactTo object clik
respondTo - reflexive notification interests

Download snippets


STANDARD TEMPLATES:

 Class.as.fdt
 Class.as.fdt.wizard
 Empty File.txt.fdt
 Event.as.fdt
 Font Library.as.fdt
 Interface.as.fdt
 Namespace.as.fdt

FABRICATION TEMPLATES:

 AsyncFabricationCommand.as.fdt
 AsyncMacroCommand.as.fdt
 FlashApplication.as.fdt
 FlashMediator.as.fdt
 FlexMediator.as.fdt
 Proxy.as.fdt
 Service.as.fdt
 SimpleCommand.as.fdt
 SimpleFabricationCommand.as.fdt

Download all templates


AS3: Results of casting primitive types

I have many bugs in my code connected with incorrect casting. To avoid them I’ve created small class to list all interesting cases:

String (1               :String)             = 1
String (0               :String)             = 0
String (0               :int)                = 0
String (1               :int)                = 1
String (true            :String)             = true
String (false           :String)             = false
String (true            :Boolean)            = true
String (false           :Boolean)            = false
String (null            :null)               = null
String (undefined       :undefined)          = undefined
String (NaN             :Number)             = NaN
String ([object Object] :Object)             = [object Object]
String (a,b             :Array)              = a,b
String (                :Array)              =
Number (1               :String)             = 1
Number (0               :String)             = 0
Number (0               :int)                = 0
Number (1               :int)                = 1
Number (true            :String)             = NaN
Number (false           :String)             = NaN
Number (true            :Boolean)            = 1
Number (false           :Boolean)            = 0
Number (null            :null)               = 0
Number (undefined       :undefined)          = NaN
Number (NaN             :Number)             = NaN
Number ([object Object] :Object)             = NaN
Number (a,b             :Array)              = NaN
Number (                :Array)              = 0
int (1                  :String)             = 1
int (0                  :String)             = 0
int (0                  :int)                = 0
int (1                  :int)                = 1
int (true               :String)             = 0
int (false              :String)             = 0
int (true               :Boolean)            = 1
int (false              :Boolean)            = 0
int (null               :null)               = 0
int (undefined          :undefined)          = 0
int (NaN                :Number)             = 0
int ([object Object]    :Object)             = 0
int (a,b                :Array)              = 0
int (                   :Array)              = 0
Boolean (1              :String)             = true
Boolean (0              :String)             = true
Boolean (0              :int)                = false
Boolean (1              :int)                = true
Boolean (true           :String)             = true
Boolean (false          :String)             = true
Boolean (true           :Boolean)            = true
Boolean (false          :Boolean)            = false
Boolean (null           :null)               = false
Boolean (undefined      :undefined)          = false
Boolean (NaN            :Number)             = false
Boolean ([object Object]:Object)             = true
Boolean (a,b            :Array)              = true
Boolean (               :Array)              = true

By the way I’ve recalled about library – as3-commons and its’ module Lang, which contains StringUtils class. It gave me ability to create quickly good looking traces. Small things gives great joy…


package as3
{
	import flash.utils.describeType;
	import org.as3commons.lang.StringUtils;
	/**
	* @author parhelium [mail-at-parhelium-dot-pl]
	* 2011-01-29 11:15
	*/
	public class primitives
	{
		private var test:Array = ["1", "0", 0, 1, "true","false",true, false, null, undefined, NaN, { }, ["a","b"],[]]
		private var types:Array = [String, Number, int, Boolean]
		public function primitives() {
			for each(var c:Class in types) {
				for each (var item:* in test) {
					makeTest(item,c);
				}
			}
		}
		private function makeTest(obj:*, castToType:*):void {
			var s:String = "" + claz(castToType) + " (" + obj
			s = StringUtils.rightPad(s, 24, " ")
			s += ":" + claz(obj)+")";
			s = StringUtils.rightPad(s, 45, " ")
			s +=  "= "+castToType(obj);
			trace(s)
		}
		private function str(obj:*):String {
			return obj+"  :"+claz(obj)
		}
		public static function claz(claz:*):String {
			if (claz === null) return "null";
			if (claz === undefined) return "undefined";

			var x:XML = new XML(describeType(claz));
			return String(x.@name).replace(/(.*)::(.*)/, "$2");
		}
	}
}

Automatic disk mounting at linux startup

It’s really useful to have disk mounted at startup. Searching in manual informations about configuring /etc/fstab file is some kind of solution , but i’m lazy and would like to have copy&paste solution.
I have found useful software to easily configure /etc/fstab, it’s called pysdm.
You can install it by typing in console:

sudo apt-get install pysdm

In result of using pysdm you get sth similar to:

proc               /proc        proc  nodev,noexec,nosuid         0  0
UUID=862f4543-b281-43f7-8de4-724b5c9714ba  /            ext4  errors=remount-ro     0  1
UUID=7b1604e4-402a-4d72-89a8-81582f266a96  none      swap  sw
/dev/sdb6      /media/x  ntfs  defaults	0  0
/dev/sdb7      /media/y  ntfs  defaults  0  0
/dev/sda6      /media/e  ntfs  defaults  0  0
/dev/sda5      /media/d  ntfs  defaults  0  0

Where is your TOV ? Quit Your Job and Find Your Work.

That’s simply stunning:


Advertising: Throw out captcha

I’ve found very interesting video about new way to advertise. Let’s see that:

Solve Media from Solve Media on Vimeo.


Groovy: remove unexpected duplications of images

GroovyConsole with my code


Today i realised that in one of my photo album (“D:/Entertainment/photos/2010/20100814″) there are many duplications (one for each file).
It looked like here:

_MG_9884.CR2
_MG_9884.xmp
_MG_9884-1.CR2
_MG_9884-1.xmp

I thought it’s time for groovyConsole :-)
Solution was incredibly simple and intuitive:

new File("D:/Entertainment/photos/2010/20100814")
    .eachFileMatch(~/(.*?)-1\.(CR2|xmp)/){ file ->
        println file.name
        file.delete();
    }

Gradle: ant scp task hangs…

I’m just playing with gradle (“A better way to build.”).
Had problem with ant scp task hanging – I couldn’t send whole directory because it hangs.
Almighty google helped me finding solution. It’s a problem with proper version of jsch-0.x.xx.jar library.
Searches show that the last working library is jsch-0.1.29.jar with ant-jsch-1.7.0.jar.
It tooks me only 2 hours to solve that… Hope you will save your time :-)
Enjoy !


SQL queries to change collation in wordpress

Simple queries to change collation in every table:


ALTER TABLE `wp_commentmeta` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_comments` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_links` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_options` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_postmeta` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_posts` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_term_relationships` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_term_taxonomy` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_terms` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_usermeta` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_users` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_woo_custom_nav_menus` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;
ALTER TABLE `wp_woo_custom_nav_records` CONVERT TO CHARACTER SET utf8 COLLATE utf8_polish_ci;

Automatically focus swf in browser on start

Recently I finished site for my friend who set up the band called “nebo“. The aim was to make clean and simple design with one extra feature – browsing their first album “Chwala i czesc” in 3d environment (3d cover). It’s easy to rotate and resize album by using keyboard and mouse scroll. After some attempts and googling, finally I achieve the goal – swf file is focused in browser by javascript in the beginning.

How to gain focus on swf file in any browser on load ?

In your html file put code:

var randomnumber=Math.floor(Math.random()*10000);
var attributes = { id:'frame', name:'frame' };
function  setupSWFObjectFocus()	{
    var swf = document.getElementById("frame");
    swf.focus();
}
swfobject.embedSWF("nebo.swf?"+randomnumber,
                              'frame',
                              '100%',
                              '100%',
                              '10.0.0',
                              'assets/swfobject/expressinstall.swf',
                              {},
                              {   bgcolor: '#000000',
                                   menu: 'false',
                                   allowFullScreen: '},
                              attributes,
                              {},
                              setupSWFObjectFocus
);

In flash file invoke method setupSWFObjectFocus from javascript by using:

import flash.external.ExternalInterface;
...
ExternalInterface.call("setupSWFObjectFocus");

And that’s all.
It’s important to note, that above solution doesn’t require you to use wmode:opaque. You can simply use default value for wmode. My experience is that default (wmode:window) value provides better perfomance than opaque one.


Latex – tip for disabling *sections in table of contents

I’ve just found solution for disabling ‘subsection’ or ‘subsubsection’ from table of contents in latex.
What’s important that solution doesn’t affect ‘*section’ number in text.

To disable subsubsections in TOC write:

  \tableofcontents
  \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}

To disable subsections in TOC write:

  \tableofcontents
  \addtocontents{toc}{\protect\setcounter{tocdepth}{1}}

Source