miscellaneous notes on flash-centric technologies (flash ide/flex/air/blazeds)...mainly focused on actionscripting for each
excellent primer material: as3 with mxmlc as3 with flash cs3
stage ~= window (or window.document?) root ~= html or document.documentElement (or document.body?) "var type; // default value var untyped:*; // (or no typing) undefined var boolean:Boolean; // false var number:Number; // NaN var integer:int; // 0 var unsignedInteger:uint; // 0 var string:String; // null var object:Object; // null variables instantiated with var cannot be deleted, just zeroed out: also true of timeline sprite methods addChild addChildAt removeChild removeChildAt numChildren getChildAt getChildByName getChildIndex setChildIndex swapChildren swapChildrenAt
tools, docs:
labs, docs, AS3 in Flash, Flex3 beta, blazeds, air/info, sqlite
as3query: alpha ver jQuery docs (part of spark??), swfassist (and other really cool stuff)
svn co http://snippets.libspark.org/svn/as3/as3Query/
mxml/actionscript syntax highlighting (for vimdir/vimVv/syntax/) mxml.vim/actionscript.vim
8/2008: After working with AS3 and these syntax files I can say that the actionscript.vim file needs quite a bit more work to really be usable. Something I hope to do myself if I get time. As far as I know the best source for the apache (or iis or other) modules is through opensource.adobe.com, possibly this place: http://opensource.adobe.com/wiki/display/flexsdk/Downloads What follows are comments from late 2007 or so that might be outdated.
satay flash object (required elements, write into page with external script [script src=some.js] to get around the ie eolas click feature): <object type="application/x-shockwave-flash" data="path/to.swf" width="300" height="300"> <param name="movie" value="path/to.swf" /> <param name="flashvars" value="custom_vars" /> <param name="allowScriptAccess" value="always|samedomain|never" /> <param name="wmode" value="transparent" /> <a href="http://www.adobe.com/go/getflashplayer"><img src="alt/content.gif" width="200" height="100" alt="alt filler for flash object" /></a> </object> flexsdkdir/templates/default.html used for module-compiled-swf response flv content-type (directive for apache, ie add to your .htaccess or conf): AddType video/x-flv .flv AddType application/vnd.adobe.air-application-installer-package+zip .air
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.net.*;
import flash.text.TextField;
import flash.text.StyleSheet;
import flash.external.ExternalInterface;
import com.nitoyon.as3query.*;
// not elegant, but should get the ball rolling......
$(this).attr({scaleMode: "noScale", align: "TL", frameRate:20});
var $$ = {
v: ["hi", "blah", "ok then","nav igate", "summer","winter"],
b: ["http://arstechnica.com", "http://nytimes.com", "http://google.com", "http://google.com", "http://google.com", "http://google.com"],
l: null,
w:100, h:30, o: 3,
fv: []
};
/*
var allFonts:Array = Font.enumerateFonts(true);
for(var j:uint = 0;j<allFonts.length;j++) trace(allFonts[j].fontName);
*/
for(var prop in root.loaderInfo.parameters) $$.fv.push(prop.concat(' is: ', root.loaderInfo.parameters[prop]));
$(Sprite).attr({id:'menu',x:10,y:50}).appendTo(root);
var u;
try{ u=root['crack'] || 'undefined'; }catch(e){
}
for(var i:uint = 0;i<$$.v.length;i++){
$(Sprite).attr({x:$$.w*i,y:0, id: 'nav'.concat(i), useHandCursor:true, buttonMode:true }).click(function(e:Event){
var url = $$.b[$(this).attr('id').replace(/^nav/, '')] || null;
ExternalInterface.call('alert', "click "+$(this).attr('id')+'\n'+url+'\nflashvars:\n'+ ($$.fv.length ? $$.fv.join('\n') : 'no flashvars'));
//navigateToURL(new URLRequest(url), '_self'); // equivalent to old getUrl() method
}).mouseover(function(e:Event){
$$.sub(this.x);
}).appendTo('#menu');
$$.l = $('#nav'+i)[0];
$$.l.graphics.beginFill(0x000000);
$$.l.graphics.drawRect(0, 0, $$.w, $$.h);
$$.l.graphics.endFill();
$(TextField).css("a",{color:'#ffFFff', fontFamily:'Scala Sans-Bd', fontSize:'12px', cursor:'pointer'})
.attr({embedFonts:true, selectable:false, width:$$.w, height:$$.h, x:0, y:0, autoSize:TextFieldAutoSize.NONE, wordWrap:true, background:false, backgroundColor:0x000000})
.text("<a href='"+$$.b[i]+"'>"+$$.v[i]+"</a>")
.appendTo('#nav'+i);
$(Sprite).attr({alpha:0, x:0,y:0, useHandCursor:true, buttonMode:true, id:'btn'+i}).appendTo('#nav'+i);
$$.l = $('#btn'+i)[0];
$$.l.graphics.beginFill(0xccff00);
$$.l.graphics.drawRect(0, 0, $$.w, $$.h);
$$.l.graphics.endFill();
} // for i
$(Sprite).attr({alpha:0,x:0,y:0, id:'border'}).appendTo('#menu');
$$.l = $('#border')[0];
$$.l.graphics.lineStyle(3, 0xffFFff);
$$.l.graphics.moveTo(0, 0);
$$.l.graphics.lineTo($$.w, 0);
$$.l.graphics.lineTo($$.w, $$.h);
$$.l.graphics.lineTo(0, $$.h);
$$.l.graphics.lineTo(0, 0);
$$.sub = function(l:Number):void{
$('#border').attr({alpha:1});
$$.driver.t.stop();
$$.driver.to = l;
$$.driver.t.start();
}
$$.driver = function():void{
var a:Object = arguments.callee;
var dx:Number = (a.to - $$.l.x) * a.eas;
if(Math.abs(dx) < 10){ $$.l.x = a.to; a.t.stop(); }
else $$.l.x += dx * a.eas;
}
$$.driver.eas = 0.9;
$$.driver.t = new Timer(Math.floor(1000/stage.frameRate));
$$.driver.t.addEventListener("timer", $$.driver);
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
//[SWF(backgroundColor="#ccff00"), width="1200", height="1400"]
var $ = {
activeBox: null,
gesture: function(e){
switch(e.type){
case 'mouseMove':
if(!$.activeBox) return;
$.activeBox.target.x = (mouseX - $.activeBox.offsetX), $.activeBox.target.y = (mouseY - $.activeBox.offsetY);
break;
case 'click':
if(e.target != e.currentTarget) return;
// clicked the stage
var d=new Sprite();
stage.addChild(d);
d.x = mouseX-50, d.y=mouseY-50;
d.graphics.beginFill(0xccff00);
d.graphics.drawRect(0, 0, 100, 100);
d.graphics.endFill();
d.buttonMode = true;
d.useHandCursor = true;
d.addEventListener(MouseEvent.MOUSE_DOWN, $.dragStart);
break;
case 'mouseUp':
if(!$.activeBox) return;
e.target.removeEventListener(MouseEvent.MOUSE_MOVE, $.mv);
if(e.target != e.currentTarget){
// sprite within stage area
$.dragEnd(e);
}else{
// cursor off stage and part or all of sprite too
var x = mouseX - $.activeBox.offsetX;
var y = mouseY - $.activeBox.offsetY;
if( x < -97 || y < -97 || x > (stage.stageWidth-3) || y > (stage.stageHeight-3)){
stage.removeChild($.activeBox.target); //$.activeBox.target.x = $.activeBox.target.y = 100;
};
$.dragEnd(e);
};
break;
};
},
dragEnd: function(){
$.activeBox.target.removeEventListener(MouseEvent.MOUSE_MOVE, $.mv);
$.activeBox.c.color = 0xccff00;
$.activeBox.target.transform.colorTransform = $.activeBox.c;
$.activeBox.target.alpha = 0.2;
$.activeBox.target.addEventListener(Event.ENTER_FRAME, $.fade);
$.activeBox = null;
},
dragStart: function(e){
$.activeBox = {
target: e.target,
offsetX: e.localX,
offsetY: e.localY,
c: e.target.transform.colorTransform
};
e.target.addEventListener(MouseEvent.MOUSE_MOVE, $.mv);
$.activeBox.c.color = 0x00ffff;
e.target.transform.colorTransform = $.activeBox.c;
e.target.alpha = 0.2;
stage.addChild(e.target);
e.target.addEventListener(Event.ENTER_FRAME, $.fade);
},
mv: function(e){ e.updateAfterEvent(); },
fade: function(e){
var a = (e.target.alpha +=0.1);
if(a >= 1) e.target.removeEventListener(Event.ENTER_FRAME, $.fade);
},
orphans: function(){
// look @ all the sprites, if any are offscreen slide them into a central area
// http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html
trace('resize', stage.numChildren); // stage.getChildAt(i);
},
ht: stage.stageHeight,
wd: stage.stageWidth
};
stage.addEventListener(MouseEvent.CLICK, $.gesture);
stage.addEventListener(MouseEvent.MOUSE_UP, $.gesture);
stage.addEventListener(MouseEvent.MOUSE_MOVE, $.gesture);
stage.addEventListener(Event.RESIZE, $.orphans);
socket related:
http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html