Tilegame level editor in Flex
In my spare time I’ve been working on a tile-based level editor. It is still in development, but has the basics covered. The idea is to make it available for free when it is done. It will be a standalone Air application (so it can save files to the disk) and hopefully will become a full game development tool. Here a video of the basic features currently available, if you are interested to beta test the app when it is done leave a message with your email so I can contact you when the beta is ready.
I got inspired making this editor when I was reading this tile game tutorial by Mattias Stridsman. I wrote a tilescrolling script based on this tutorial that will be used for previewing and testing the levels within the editor. In my opinion this way of making game levels is more versatile than using grid based tile levels where each tile needs to be defined, where in Mattias’s example you cluster tiles in one rectangle so that you only describe the position, dimensions and graphic of the tile.
The artwork used in the video is by David Baumgart
Filed under Actionscript 3, Air, Flash, Flash Games, Flex | Comments (2)Alpha blending CSS TextFields in ActionScript 3
The problem I encountered with CSS driven TextFields in AS3 was that I was no longer able to use “embedfonts = true” to be able to set the TextField alpha. To solve this issue you can use blendModes on the TextField object, as in the following:
myTxtField.blendMode = BlendMode.LAYER; myTxtField.alpha = 0,5;
This also works with a mask over a textfield.
Example
Do realise that using blendmodes you increase the clients CPU load.
Filed under Actionscript 3, Flash, Flex, linkedin | Comment (0)Arch.Maaik game
Last saturday we launched the Arch.Maaik game at his 5 year anniversary. The game is currently being prepared for online use and will be here in a few weeks.

The game was realised together with Matt Baay (in-game gfx) and Eric Weterings (intro animation & sound).

WNF Rangergame
Last month in cooperation with MediaRijk we developed a topview game for WWF that was part of the tv show and can be played online on the Jetix site.
Click the image to play the game.
You can watch the broadcasts on Jetix each sunday starting March 1st at 10:40.
Flash Media Server Eclipse/Flex Builder plugin
I stumbled upon this FMS plugin for Eclipse. Unfortunately it is beta and never finished, but it still helps enough to write your FMS apps allot faster. It was originally available on fczone.net but for some reason that site is no longer part of the internets.To install, just drop it in you Eclipse/Flex Builder plugin folder.
Filed under Actionscript 3, Flex | Comments (3)
Simple way to protect your SWF from being ripped
When making a Flash component most of us try to make it as dynamic as possible, often to using XML to configure and feed the application. I personally sell small Flash components on FlashDen that all use XML to get image addresses or global settings. The FlashDen website requires you to submit a preview file to show how the application works, but in most cases this also gives you the key to the product. Although the SWFs are obfuscated, you still can download the XML and the swf, fill the XML with your own data and use it without purchasing the source. In order to prevent this one of the FlashDen member (Alex Pica) wrote a class to check the current domain and returns a false Boolean if the file is not on the right domain. The AS 2.0 class by Alex Pica:
/** * @author Alex PICA * @version 1.0 * * Class: FlashDenPreviewFileProtection * Description: I made this class to prevent the theft of the preview files from flashden.net */ import mx.utils.CollectionImpl; import mx.utils.IteratorImpl; class net.alexandrup.common.FlashDenPreviewFileProtection { //this var will be set to true when compiling preview files public static var IsPreviewFile:Boolean = false; /** * Tests if the current SWF file is stolen * @return TRUE if it is a stolen swf */ public static function isStolenSWF():Boolean { //do not check if this is the fullversion file if (IsPreviewFile === false) return false; var _domain:String = (new LocalConnection()).domain(); var _allowedDomainList:CollectionImpl = new CollectionImpl(); //------- add here all strings that would have to be found in allowed domain names --------o _allowedDomainList.addItem("flashden"); _allowedDomainList.addItem("localhost"); //add localhost and 127.0.0.1 to be able to run locally _allowedDomainList.addItem("127.0.0.1"); //--------------------------------------------o var _it:IteratorImpl = IteratorImpl(_allowedDomainList.getIterator()); while (_it.hasNext()) { if (_domain.toLowerCase().indexOf(_it.next().toString().toLowerCase(), 0) > -1) { return false; } } return true; } //private constructor to prevent instantiation private function FlashDenPreviewFileProtection() { }; } Just copy/paste it and change the package to whatever you like. Usage: net.alexandrup.common.FlashDenPreviewFileProtection.IsPreviewFile = true; if (!net.alexandrup.common.FlashDenPreviewFileProtection.isStolenSWF()) { this.Init();//here is where you initialize your application } else { var txt:TextField = _root.createTextField("err_txt", 1, 0, 0, Stage.width, Stage.height); txt.multiline = true; txt.textColor = 0xFF0000; txt.text = "This file is stolen from www.flashden.net."; }
AS3 Rewrite by me:
/** * @author Boy Carper - Toybot Interactive * @version 1.0 * * Class: FlashDenPreviewFileProtection * Description: This is a AS3 rewrite of the original AS2 class by Alex PICA. * The class prevents the theft of the preview files from flashden.net * * Usage: var loader:URLLoader = new URLLoader(); FlashDenPreviewFileProtection.addAlowedDomain("www.flashden.com"); FlashDenPreviewFileProtection.addAlowedDomain("flashden.com"); FlashDenPreviewFileProtection.addAlowedDomain("localhost"); FlashDenPreviewFileProtection.addAlowedDomain("127.0.0.1"); if(!FlashDenPreviewFileProtection.isStolenSWF(root)) loader.load(new URLRequest("pathtoyourxml.xml")); * * */ package com.toybot.flashden { public class FlashDenPreviewFileProtection { private static var _isPreviewFile:Boolean = true; private static var _allowedDomains:Array = new Array(); public static function isStolenSWF(_root:Object):Boolean { var i:int; for(i=0;i<_allowedDomains.length;i++) { if(String(_root.loaderInfo.url).indexOf(_allowedDomains[i])!=-1) return false } return true; } public static function addAlowedDomain(domain:String):void { _allowedDomains.push(domain); } } }
The examples are focussed on the flashden domain, but can of course be used for any domain.
Filed under Actionscript 3 | Comments (7)BitmapData/draw() and checkPolicyFile
Today I ran into the following error:
SecurityError: Error #2122: Security sandbox violation: BitmapData.draw: http://exampledomain.com/file.swf cannot access http://exampledomain.com/images/image.jpg. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
The error was generated by a class in our util folder that we use quite much, but we never had this problem. Well as the error is mentioning, the checkPolicyFile is not set because the LoaderContext is set to null when you don’t supply one in the Loader.load(request:URLRequest, context:LoaderContext = null):void. The strange thing is that the browser is loading the images, only when I create a bitmap and want to draw() the bitmapData I get the above error. I don’t get why it doesn’t check the policyfile when I request the image from a different domain. In order to get rid of the error I did the following:
1 2 3 | var loaderContext:LoaderContext = new LoaderContext(); loaderContext.checkPolicyFile = true; Loader(_loader).load(_req,loaderContext); |
So adding the loaderContext with checkPolicyFile on true does the trick.
Filed under Actionscript 3, Error handling AS3, Flash, Flex | Comments (8)onBWDone problem Flash Media Server with AS3
I ran into a small problem today while testing FMS 3, and had some problems finding the solution. I eventually found it and would like to share it with you.if you get the error:
ReferenceError: Error #1069: Property onBWDone not found on StreamTest and there is no default value.
Make sure that you map your NetConnection.client to a client class or the class you are working from. Then create the method onBWDone in the target Class. :
1 2 3 4 5 6 7 8 9 10 11 12 13 | private function setConnection():void { nc = new NetConnection(); nc.client = this; nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError); nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError); nc.connect(appURL); } public function onBWDone():void{ } |
Why is this happening?
Well if you look into the VOD application on the FMS server you will see that the application performs a BandWidth check and invokes this function on the client when it is done. You can measure the bandwidth speed in order to select a proper stream (assuming you have encoded multiple bitrates of one video). How to use this?
Take a look here.
AS3 onReleaseOutside
It seems to be that the ReleaseOutside we all know from Actionscript 2 is no more in AS3. Why? I don’t know. I noticed allot of people having problems with this lack of feature. The work around has been published all over the web, another reference here will help spread the word. The idea of an onReleaseOutside MouseEvent is that you detect if the mouse is not over the object when it is up. So what you simply need to do is relocate the MouseEvent.MOUSE_UP from the object you want to detect to the stage. So what does this look like?
// constructor public function MyClass() { //we use this event to obtain the stage object addEventListener(Event.ADDED_TO_STAGE, onAdded); } // stage object is now available private function onAdded(e:Event):void { addChild(_yourbutton); _yourbutton.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); } private function onMouseDown(me:MouseEvent):void { trace("mouse down"); stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp) } private function onMouseUp(me:MouseEvent):void { trace("mouse up"); stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp) }
I hope you find this useful.
Filed under Actionscript 3, Flash, Flex | Comment (0)LocalConnection and ExternalInterface
For my Flashden portfolio I made an example of the different ways of communicating between different SWF’s and the browser. It demonstrates the bi-directional usage of LocalConnection and ExternalInterface.
It is written in AS3 together with a little piece of javascript and needs to be run in a webserver environment to avoid sandbox violations.
Filed under Actionscript 3, Flash, Flex | Comment (0)
