Archive for the ‘ActionScript’ Category

Sixers Shout n’ Shoot

Thursday, May 8th, 2008

Wachovia Center
View from the press box

Well, I finally got the chance to run down to the Wachovia Center in Philadelphia to see the Shout n’ Shoot mobile billboard game that I worked on with the Play MegaPhone crew. Sadly, the Sixers lost to Detroit, but I did get to go behind-the-scenes before and during the game. 

Ironically, despite how much time I spent programming it, I couldn’t score as much on the game as some other fans (I blame my smart phone’s noise reduction). Supposedly the game is running down on South St. for a little while still, so hopefully I’ll get the chance to try again. Otherwise, I’ll just have to see the Sixers again next season.

FCNY AS2.0 to AS3.0 Migration Link

Thursday, January 17th, 2008

Here’s the link on a presentation I gave last night on Actionscript 2.0 to 3.0 migration at FlashCodersNY. There are so many great resources out there on the topic already…I decided to take a different route and provide simple FLA examples to help people get started. Hope it helps someone out.  

GoASAP Tween Platform for ActionScript 3.0

Wednesday, January 16th, 2008

I finally found some free time at the beginning of the month to work with the AS3 Go Tween platform. It’s still in its infancy, but I hope to continue to build/contribute to it. Donovan Adams already has started an object syntax Go Tween class, but I could imagine a filter class, volume class, physics class, etc.

So, why am I still fiddling with this instead of using the perfectly satisfactory Tweener or TweenLite, you ask? Check the benchmarks.

Honestly, it’s not just the benchmarks, it’s the philosophy this project provides. Oh, and it also has built-in sequencing, something I’ve really missed from my AS2 + Fuse days.

Anyway, here’s a simple colorTransform tween class I quickly threw together. Hopefully, someone’ll find this and integrate it into something better…
/**
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.hauckinteractive.tween {
import flash.display.DisplayObject;
import org.goasap.items.LinearGo;
import flash.geom.ColorTransform;
/**
* Simple Tween class that changes the tint of a DisplayObject.
* @author Rich Hauck
* @version 2008-01-07
*/
public class ColorTransformTween extends LinearGo{
protected var _target : DisplayObject;
protected var _targetTint : Number;
protected var _startColor:ColorTransform;
protected var _endColor:ColorTransform;
/**
* Constructor.
* @param target DisplayObject
* @param tint Hexidecimal value (0xFFFFFF)
* @param delay Delay in seconds before performing tween
* @param duration Number of seconds for animation to play
* @param easing type of easing
* */
public function ColorTransformTween(target:DisplayObject = null, tint:Number=NaN, delay:Number = NaN, duration:Number = NaN, easing:Function = null){
super(delay, duration, easing);
_target = target;
_targetTint = tint;
}
/**
* Instantiates and auto-starts class.
* */
public static function go(target:DisplayObject = null, tint:Number=NaN, delay:Number = NaN, duration:Number = NaN, easing:Function = null):void {
var ctTween:ColorTransformTween = new ColorTransformTween(target, tint, duration, delay, easing);
ctTween.start();
}
/**
* Begins tween.
* @return Boolean true if _target is defined.
* */
override public function start():Boolean{
if (!_target){
return false;
}
_startColor = _target.transform.colorTransform;
_endColor = new ColorTransform();
if(!isNaN(_targetTint)){
_endColor.color = _targetTint;
}
return (super.start());
}
/**
* Loop performing tween.
*
* */
override protected function onUpdate(type:String) : void {
_target.transform.colorTransform = interpolateColor(_startColor, _endColor, _position);
}
/**
* Mixes between starting colorTransform and target ending colorTransform.
* @param start current colorTransform of DisplayObject
* @param end target colorTransform of DisplayObject
* @param t incrementing value from 0 to 1
* @ return ColorTransform instance.
* */
private function interpolateColor(start:ColorTransform, end:ColorTransform, t:Number):ColorTransform {
var result:ColorTransform = new ColorTransform();
result.redMultiplier = start.redMultiplier + (end.redMultiplier - start.redMultiplier)*t;
result.greenMultiplier = start.greenMultiplier + (end.greenMultiplier - start.greenMultiplier)*t;
result.blueMultiplier = start.blueMultiplier + (end.blueMultiplier - start.blueMultiplier)*t;
result.alphaMultiplier = start.alphaMultiplier + (end.alphaMultiplier - start.alphaMultiplier)*t;
result.redOffset = start.redOffset + (end.redOffset - start.redOffset)*t;
result.greenOffset = start.greenOffset + (end.greenOffset - start.greenOffset)*t;
result.blueOffset = start.blueOffset + (end.blueOffset - start.blueOffset)*t;
result.alphaOffset = start.alphaOffset + (end.alphaOffset - start.alphaOffset)*t;
return result;
}
}
}

AS2 to AS3 @ FCNY

Tuesday, January 15th, 2008

*SHAMELESS PLUG*

I’ll be presenting leading a discussion on migrating from Actionscript 2.0 to Actionscript 3.0 at tomorrow evening’s FlashCoderNY (FCNY) meeting. Meetings are at 7 pm Wednesdays in the basement of Think Coffee (248 Mercer between 3rd and 4th).

I say ‘leading a discussion’ because FCNY meetings tend to migrate towards the group interest, however, I will share some AS3 examples I’ve created. Anyways, I always learn something when I attend FCNY and invite you to come check it out.

HTMLWrapper–Render XHTML in Flash

Thursday, January 10th, 2008

Tyler Larson presenting htmlwrapper…Tyler’s always playing mad scientist with ActionScript, so I felt compelled to attend a recent FlashCodersNY meeting to check this out.

In short, I’d equate htmlwrapper to siFR on crack–instead of replacing just an <h1>, htmlwrapper hides the rendered HTML page (ala swfobject) and replaces it with an SWF that parses the CSS and renders the page.

It’s still a bit young (it provides an impressive CSS selector support, but not tables), but I could see this easily spicing up static pages–provided a non-Flash equivalent is made, too.

Referencing the Flash CS3 Document Class from within a MovieClip

Thursday, November 1st, 2007

I’m posting this hoping to find a better answer than what I’ve come up with, as well as help others that have run into this problem.

With Flash CS3, you can now define a Document class in the properties window. This class extends MovieClip and essentially represents your Flash movie. Below is an example of a document class called Main.as:

package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public function sayHi():void {
trace("hi!");
}
}
}

Now, if I wanted to call the function sayHi() within my main timeline, I could just call sayHi() within a keyframe. It’s a little different when attempting to call via a MovieClip on the main timeline, however. After trying parent.sayHi() and root.sayHi() and receiving compiler errors, I found this hack. I’m not into using wildcards, so I instead use this in the timeline of my embedded MovieClip:

var main:Object = this.parent;
main.sayHi();

It’s as if the MovieClip doesn’t know its parent, so a reference needs to be made. Object is about as abstract as it gets, but when I tried getting more specific Flash didn’t like it and threw a compiler error. Here’s the inheritance chain (below). The furthest I got was DisplayObjectContainer, but since Object is easier, I stuck with that.

MovieClip > Sprite > DisplayObjectContainer > InteractiveObject >DisplayObject > EventDispatcher > Object

If anyone has a better solution please share.

Flash CS3 ComboBox setStyle() for Text

Wednesday, October 24th, 2007

I’ve been delving into Flash’s CS3 components and discovered that the typical Actionscript 3.0 setStyle() method doesn’t work with the ComboBox. The workaround is to set the styles for components within the ComboBox. Here’s an example:


var tf:TextFormat = new TextFormat();

tf.color = 0xFFFFFF;

myComboBox.textField.setStyle("textFormat",tf);
myComboBox.dropdown.setRendererStyle("textFormat", tf);


// specify "disabledTextFormat" to overwrite default
myComboBox.textField.setStyle("disabledTextFormat", tf);

Happy coding!

Flash 9 Actionscript 3.0 and Security #2137. Or Why Flash Hyperlinks Don’t Work.

Saturday, September 29th, 2007

First off, I apologize for such an SEO-friendly title to this post, but I want to make sure that no one else suffers through the searching I recently went through.

I recently worked on a site where I was using Flash 9 with AS 3.0 to build the primary menu for a Web site. The code was some simple drop back and pass (sorry, playing too much Madden these days):

private function onClick(event:Event):void {
    //_urlArray is a list of page links
    var request:URLRequest = new URLRequest(_urlArray[urlID]);
navigateToURL(request, "_self");
}

So, the site launches, and soon after, I’m getting calls from the client that the navigation links don’t do anything. It works fine in my tests, so I contact some friends to try the site. No problems. So, to see this firsthand, I go to my client’s office to test the issue, only to discover that we can’t adequately replicate the issue. I check my .htaccess, the site’s PHP framework, and conclude that it’s a DNS issue (since the site recently tranferred hosts).

The problem still occurs a day later.

So, I stop back in, and quickly discover that the Flash works fine from http://www.site.com but fails silently when the user is on http://site.com. Thanks to my trusty Flash Debugger Player, I find out it’s error 2137.

After exhaustively learning about the new Flash Player 9 security, I learn that the only thing I have to do is place the following in the <object> and <embed>:

<param name="allowScriptAccess" value="always" />
<EMBED src="file.swf" AllowScriptAccess=""></EMBED>

Alternatively, if you use SWFObject like me, you would use the following:
so.addParam("AllowScriptAccess", "always");

So what was the problem? Well Adobe integrated a new feature into ActionScript 3.0 security where setting the window type of “_self” in navigateToURL() is only allowed from the same domain. In my case, www.site.com and site.com aren’t the same domain (btw, IP != domain, either). In order for a Website to declare trust to an SWF, it has to provide it in in the HTML.

Anyhow, I hope this saves someone the time I took scrambling through Adobe Flash security docs. :)

Adobe on AIR in NYC

Monday, September 24th, 2007

airmap.jpg

I just got back from Adobe’s On AIR tour seminar in New York City. Overall, I think AIR is a really exciting project as it empowers Flash, Flex, and AJAX developers to easily create and deploy desktop applications. I think Adobe has gone in the right direction by providing the SDK for free (take that, Silverlight!). The ActionScript-built Web browser demo was impressive, and Adobe should seriously consider having new hire Lee Brimelow do all of evangelistic Keynote presentations.

adobebus.jpg

All that said, I have to ask, how many applications does the average user currently use that require an Internet connection? I guess what my point is is that while I’m interested in seeing what the development community comes up with, I really can’t see AIR replacing most Web-based services or revolutionizing an industry. What I can see is easier deployment of, say, sales applications for both offline and online purposes, and what I hope to not see are uninspired renditions of the typical “VIRAL-Social-Networking” media player running on the desktop. I’m sure to be delightfully surprised with what everyone comes up with, but I figured I’d just throw a grain of salt along with the excitement of the show.

bus.jpg

I should also mention that they tantalized the crowd with talks of an Adobe standalone Video Player (finally!) and AIR mobile (I tried to get more information out of Mike Chambers, but no dice).

firehouse.jpg

its-it.jpg

Go Animation Package for AS3

Sunday, September 23rd, 2007

Well, my friend Moses has announced Go for ActionScript 3.0. No, it’s not Fuse 3–actually, I think it leapfrogs the standard ActionScript animation library idea, and I hope it’s successful at getting people to work together on coding concepts, rather than release their own flavors of tween engines and hope for industry stardom.

I’ve been privileged to beta test Go, and the benchmarks alone are pretty impressive. I won’t let any cats out of the bag, but will say that it’s challenged me to wonder if subclassing is more ideal than using a decorator pattern. Personally, I lean towards subclassing since it requires some preplanning. Furthermore, decorators provide runtime changes, functionality that for some reason I wouldn’t feel comfortable with unless absolutely necessary. What do you think, though?


Bad Behavior has blocked 349 access attempts in the last 7 days.