Red & Blue
Friday, August 14th, 2009little actionscript experiment I did during a break.
download the code: Red-Blue
little actionscript experiment I did during a break.
download the code: Red-Blue
today I published my first air application, called iSurveill. A simple webcam surveillance application that takes snapshots with a webcam and saves them to the computer. It’s not very sufisticated but as a first try it will do. The application is now available on my website http://www.chrillo.info/isurveill/ and hopefully it will soon be available in the adobe air market place.
actionscript 3 does not nativly support a onReleaseOutside Event. When creating things like a scrollBar or other UI elements this can be quite annoying.
Here is a simple work around that uses a simple movieClip as a button:
import flash.display.MovieClip
import flash.events.*
var myBtn:MovieClip=new MovieClip()
myBtn.graphics.beginFill(0x003366,1)
myBtn.graphics.drawRect(0,0,50,50)
addChild(myBtn)
myBtn.addEventListener(MouseEvent.MOUSE_DOWN,downHandler)
function downHandler(event:MouseEvent):void{
stage.addEventListener(MouseEvent.MOUSE_UP,upHandler)
trace("mouse went down")
}
function upHandler(e:MouseEvent):void{
if(e.target==stage){ // this checks to see if the event is coming from the stage or not
stage.removeEventListener(MouseEvent.MOUSE_UP,upHandler)
trace("mouse went up outside")
}else{
trace("mouse went up")
}
}
pretty simple
heres the fla for download
I finally got a copy of adobe flash cs4. In addition to the great new user interface flash cs4 can compile flashplayer 10 content which enables the new actionscript 3 3D methods. with only the three simply rotationX, rotationY and rotationZ properties one can quickly create really nice 3D animations. This is my first test.
here are the few lines of code it took to make this thing spin:
</pre>
import flash.display.*
import flash.geom.*
import flash.events.*
import flash.display.*
var panes:MovieClip=new MovieClip()
panes.x=300
panes.y=200
for(var i:Number=0;i<18;i++){
var pane:MovieClip=new MovieClip()
pane.graphics.lineStyle(1,0xffffff,0.5)
pane.graphics.beginFill(0x003366,0.3)
pane.graphics.drawRect(0,0,100,100)
pane.x=0
pane.y=-50
pane.rotationY=i*20
pane.moving=false
panes.addChild(pane)
}
addChild(panes)
panes.rotationZ=90
panes.cacheAsBitmap=true
panes.addEventListener(Event.ENTER_FRAME,movePanes)
function movePanes(e:Event){
panes.rotationX+=5
}
<pre>
I am currently moving from AS2 to AS3. This animation was one of the results while playing around with AS3
I just recently bought the book Essential Actionscript 3 by Collin Mook. I havent gotten really far into the book yet but there are few things that one must understand in order to get even started with actionscript 3. The first thing is AS 3 is pretty much OOP only, which means for you to forget about timeline code which i personally used very often especially for small projects. So where do I put my code now, was the first thing I asked my self. The answer to this question is the document class. When using the flash authoring tool you find this setting in the document preferences.
![]()
.png)
so none of your code will go to the timeline. You will need to follow a few simple steps:
package{
import flash.display.Sprite //
public class yourClass extends Sprite{
public function yourClass(){
// your first timeline frame code goes here
}
}
}
Now this is a very simplified approach to this topic, there is a lot to know about the naming of packages, classes and the scope of objects and methods within them. I highly recommend the book i mentioned above. just note that the document class must either extend the sprite or the movieclip class, and you have to import every class you want to use. In general Actionscript 3 is a lot more strict but thereby a lot more effective. It forces good OOP programing, and won’t let you get by with several hundred lines of code in you first frame.