kreativeKING - Interactive Developer

Posts tagged “AS3”

Tutorial Published in Web Designer Magazine

Just would like to let everyone know to pick up the 155th issue of Web Designer Magazine. I have been published AGAIN!! What a great feeling to see your words in a publication. Anyway, I wrote a Papervision 3D tutorial for beginning PV3D users. It is an interactive 3D Menu. By the time you get through the complete tutorial, you will know most of the basic tools for creating 3D scenes in PV3D. This isn’t a tutorial on the Great White version of Papervision, This is on the newest release of PV3D which I recommend everyone get.

Here is a link to get your issue.

New kreativeKING VideoPlayer API

I finally released the kreativeKING Videoplayer API. I’m sure you all remember the old VideoViewer and ProgressionBar classes. Well this new set of API does away with those and replaces with a plethora of new classes to make your video player creating processes much easier. Spend more time on design than on programming. Some of the 10+ classes released are VideoWindow ( Replacement of the VideoViewer Class ), VideoPanel ( ProgressionBar replacement) and the VideoControl Classes. These are the main 3 classes that you will be using to the video players logic. I will post later on a short tutorial on creating a video player using the API.



The new API allows you to load movies via flashVars or XML. Playlist support through the XML method. Keep the amount of code to a minimum of about 10 lines and your code is done. I have posted documentation online of the API for reference here. This version of the documentation will have some small changes coming in the next day or two as the API has been updated since I uploaded the documentation. But the gist of it is correct.

To get your hands on the API, you have to purchase one of my video player products from FlashDen. I know alot of people probably are ready to go to a different page after reading that, but I think its fair for the amount of time I put into creating it. Also it’s cheap, only $15. But since I’m a nice guy, I will be releasing a LITE version for free for other to play around with in the next coming weeks, even days actually. SO be on the lookout for that. I will be posting it up here once it’s completed.

Here is a small sample of what the code looks like for a completed video player


var vControl:VideoControl = new VideoControl();
var panel:VideoPanel = new VideoPanel(movie, cBar.progress);
var assets:Array = [movie, panel, cBar.playB, cBar.muteB];

movie.addEventListener(Event.COMPLETE, setupMovie);

vControl.setupAssets(assets);
vControl.useXML();

function setupMovie(e:Event):void
{
vControl.setup();
}




This code creates a video player with a mute button, playPause button and progressbar.
Nice right =D

Well I will leave you all with that and some important links.

AS3 XML FlashVar VideoPlayer v1.0 w/ CG VideoPlayer API

kreativeBackground v1 - AS3 Video Background w/ CG VideoPlayer API


kreativeKING ViedoPlayer API Documentation

New AS3 Tutor

Woot!!!, just a really small post. You are reading this post from the new AS3 Tutor at the Borough of Manhattan Community College. I actually got the good news a couple days ago, but I would like to share it with the world =D.


In addition, if anyone needs any help with Actionscript 3.0 or needs a private tutor, don’t hesitate to drop me an email. In the next coming days I have some interesting things to post about ranging from new FlashDen products to new published articles. So be on the lookout for those, or you know what is even better?? Just subscribe and I’ll let you know. =D Happy Flashing people.





Upcoming Topics




  • NEW FlashDen Products (VideoPlayes - Image Viewers)

  • NEW Tutorial Articles

  • NEW CG VIdeoPlayer API Documentation

  • NEW Video Tutorials (I really mean it this time =D)

Javascript and Actionscript Conversation

This weekend my good friend Peter Panton asked my for some help setting up some communication between Javascript and Actionscript. He wanted to be able to get the scroll value of the HTML page and use it in Flash. To be honest, I never did any kind of communication between the two and had no idea where to start. I did some research and came across the ExternalInterface Class.



It took me a while to get how exactly the class worked, but once I got a handle on it, setting up the relation was easy. At first I set up a small test just to see if I can pass information back and forth. Basically is just passes string from the HTML page to Flash and vice versa. You can check it out at ExternalInterface Test 1. All the code will be at the bottom.


Once I jumped for joy with the first example, I got the scroll example to work here. The Javascript just sends the value of the scrollTop to the Flash text field. Since I’m on the Mac, Im not too sure if this works in IE, but it works just fine in FireFox and Safari. The example isn’t rocket science but I figure I’d share it anyway. I’ll even share the example files for you to play with.


Have Fun


Download Examples Here


Example 1 AS



import flash.external.ExternalInterface;

sendBut.addEventListener(MouseEvent.CLICK, toJS);

if(ExternalInterface.available)
{
try
{
ExternalInterface.addCallback("sendToFlash", fromJS);
}
catch(e:Error)
{

}
}

function fromJS($value:String):void
{
oText.text = $value;
}

function toJS(e:MouseEvent):void
{
if(ExternalInterface.available)
{
ExternalInterface.call("sendToJS", iText.text);
}
}

Example 2 AS



import flash.external.ExternalInterface;

if(ExternalInterface.available)
{
try
{
ExternalInterface.addCallback("sendToFlash", fromJS);
}
catch(e:Error)
{

}
}

function fromJS($value:String):void
{
oText.text = $value;
}

New QuickView Portfolio Mini Site

I have been applying for alot of freelance jobs lately and I don’t really have a portfolio up showcasing my flash skills. I usually just forward them here to my blog but I don’t think employers have any patience to sift through the posts. So I decided to make a little mini site that has links to my various works. It is all built in flex ( Yup, I’m learning MXML and I must say….. I like it).


This is my second Flex RIA. My first is a Flex CMS system called CGCMS, which I will be blogging about later on in the week ( stay tuned ). This is pretty cool for me as it incorporates so many technologies for it to run smoothly and be easily updated from my CMS. All the info is pulled from a database and I can update it on the fly in a matter of seconds. I think I might just do away with XML. Gonna practice more on my PHP and MySQL.

So let me know what you think. Check it out here.

AIRUploader Preview

I know I haven’t been posting as frequently as I used to, but I have good reason. The AIRUploader is one of those reasons. This is a project I have been working on in the past week and a half. It started out as just practice for learning how to use the FileReference class, but then grew to be muuuuuuch more.
This application is essentially a drag and drop FTP Uploader. I sometimes hate uploading files. Signing in, looking for directories, etc etc. So I decided to make this application. It will save your login information so you don’t have to keep entering your information.



[kml_flashembed movie=”http://blog.kreativeking.com/downloads/flash/airuploader/player.swf” bgcolor=”#222222” base=”http://blog.kreativeking.com/downloads/flash/airuploader/” height=”360” width=”600” /]


There is a bit of setup before using the app though. For one, since this uses PHP, you need to first upload the php script that handles the backend uploading and ftp connection. Its best to upload it to the root since the path to upload your files are relative, but any location would suffice.
I tried to keep it fully OOP, everything is in external classes. I actually coded the whole thing in Flash. The new views in CS4 are pretty manageable. I used the Developer View and am really loving the Project window view. Still doesn’t beat Flex Builder, but heh, we can’t have everything.
So far it only works on Mac, I haven’t implemented the windows version yet, but that will be coming out in the future. I’ll then release it to the public. Let me know if this is something you would use.

Some future features:

  • Upload Folders


  • Customized Colors


  • Sound Effects


  • Windows XP/Vista Functionaility


Mac vs PC Minisite

Here’s a project I had to do for my Multimedia Design Class. We needed to pick a subject that is up for debate. I decided to do Mac vs PC, seemed to be more fun than smoking or something like that.

I went for a fun UI approach and make it like a desktop. Click on the icons and a window pops up that you can drag around, minimize, etc. It was a pretty fun project. Best of all I got an A!!!!!!.

I also posted the code for anyone who was curious.


Check out the site here





Main SWF File



import gs.TweenLite;
import gs.easing.*;

var wL:Loader = new Loader();
var appHolder:MovieClip = new MovieClip;
var appWindow:Loader = new Loader();
var appIcon:app = new app();
var lockHolder:MovieClip = new MovieClip;
var lockWindow:Loader = new Loader();
var lockIcon:lock = new lock();
var socialHolder:MovieClip = new MovieClip;
var socialWindow:Loader = new Loader();
var socialIcon:social = new social();
var costHolder:MovieClip = new MovieClip;
var costWindow:Loader = new Loader();
var costIcon:cost = new cost();
var performanceHolder:MovieClip = new MovieClip;
var performanceWindow:Loader = new Loader();
var performanceIcon:perform = new perform();
var minimized:Boolean = false;
var cf1:ColorTransform = new ColorTransform();
var cf2:ColorTransform = new ColorTransform();
var showing:Boolean = false;

cf1.color = 0xFFFFFF;
cf2.color = 0x000000;

appHolder.addChild(appWindow);
appIcon.name = "appIcon";
appIcon.mouseChildren = false;
appIcon.buttonMode = true;
lockHolder.addChild(lockWindow);
lockIcon.name = "lockIcon";
lockIcon.mouseChildren = false;
lockIcon.buttonMode = true;
socialHolder.addChild(socialWindow);
socialIcon.name = "socialIcon";
socialIcon.mouseChildren = false;
socialIcon.buttonMode = true;
costHolder.addChild(costWindow);
costIcon.name = "costIcon";
costIcon.mouseChildren = false;
costIcon.buttonMode = true;
performanceHolder.addChild(performanceWindow);
performanceIcon.name = "performanceIcon";
performanceIcon.mouseChildren = false;
performanceIcon.buttonMode = true;

wL.contentLoaderInfo.addEventListener(Event.COMPLETE, addWall);
costWindow.contentLoaderInfo.addEventListener(Event.COMPLETE, addListeners);
performanceWindow.contentLoaderInfo.addEventListener(Event.COMPLETE, addListeners);
appWindow.contentLoaderInfo.addEventListener(Event.COMPLETE, addListeners);
lockWindow.contentLoaderInfo.addEventListener(Event.COMPLETE, addListeners);
socialWindow.contentLoaderInfo.addEventListener(Event.COMPLETE, addListeners);
appIcon.addEventListener(MouseEvent.CLICK, clickEvent);
appIcon.addEventListener(MouseEvent.ROLL_OVER, overEvent);
appIcon.addEventListener(MouseEvent.ROLL_OUT, outEvent);
lockIcon.addEventListener(MouseEvent.CLICK, clickEvent);
lockIcon.addEventListener(MouseEvent.ROLL_OVER, overEvent);
lockIcon.addEventListener(MouseEvent.ROLL_OUT, outEvent);
socialIcon.addEventListener(MouseEvent.CLICK, clickEvent);
socialIcon.addEventListener(MouseEvent.ROLL_OVER, overEvent);
socialIcon.addEventListener(MouseEvent.ROLL_OUT, outEvent);
costIcon.addEventListener(MouseEvent.CLICK, clickEvent);
costIcon.addEventListener(MouseEvent.ROLL_OVER, overEvent);
costIcon.addEventListener(MouseEvent.ROLL_OUT, outEvent);
performanceIcon.addEventListener(MouseEvent.CLICK, clickEvent);
performanceIcon.addEventListener(MouseEvent.ROLL_OVER, overEvent);
performanceIcon.addEventListener(MouseEvent.ROLL_OUT, outEvent);

stage.addEventListener(Event.RESIZE, redoWall);

wL.load(new URLRequest("wall3.jpg"));
appWindow.load(new URLRequest("applications.swf"));
lockWindow.load(new URLRequest("security.swf"));
socialWindow.load(new URLRequest("social.swf"));
costWindow.load(new URLRequest("cost.swf"));
performanceWindow.load(new URLRequest("performance.swf"));

function clickEvent(e:MouseEvent):void
{
if(e.type == MouseEvent.CLICK)
{
switch(e.target.name)
{
case "costIcon":
addCost();
costHolder.showing = true;
break;

case "performanceIcon":
addPerformance();
performanceHolder.showing = true;
break;

case "appIcon":
addApp();
appHolder.showing = true;
break;

case "lockIcon":
addLock();
lockHolder.showing = true;
break;

case "socialIcon":
addSocial();
socialHolder.showing = true;
break;

case "close":
trace("closed");
TweenLite.to(e.target.root.parent, .5, {alpha:0, onComplete:removeLoader, onCompleteParams:[e.target.root.parent]});
break;

case "minimize":
if(!e.target.minimized)
{
TweenLite.to(e.target.root.clip, .5, {alpha:0});
TweenLite.to(e.target.root, .5, {delay:.5, scaleX:.5, ease:Bounce.easeOut});
TweenLite.to(e.target.root.title, .5, {delay:.5, scaleX:2});
TweenLite.to(e.target.root.minimize, .5, {delay:.5, scaleX:2, x:"-10"});
TweenLite.to(e.target.root.close, .5, {delay:.5, scaleX:2});
e.target.root.titleBar.transform.colorTransform = cf1;
e.target.root.title.transform.colorTransform = cf2;
e.target.minimized = true;
}
else
{
e.target.root.titleBar.transform.colorTransform = cf2;
e.target.root.title.transform.colorTransform = cf1;
TweenLite.to(e.target.root, .5, {scaleX:1, ease:Bounce.easeOut});
TweenLite.to(e.target.root.title, .5, { scaleX:1});
TweenLite.to(e.target.root.minimize, .5, {scaleX:1, x:"+10"});
TweenLite.to(e.target.root.close, .5, {scaleX:1});
TweenLite.to(e.target.root.clip, .5, {delay:.5,alpha:1});
e.target.minimized = false;
}
break;
}
}
else if(e.type == MouseEvent.DOUBLE_CLICK)
{
trace(e.target.name);
switch(e.target.name)
{

}
}
}

function overEvent(e:MouseEvent):void
{
TweenLite.to(e.target, .4, {scaleY:1, scaleX:1});
}

function outEvent(e:MouseEvent):void
{

TweenLite.to(e.target, .1, {scaleY:.8, scaleX:.8});
}

function upDownEvent(e:MouseEvent):void
{
if(e.type == MouseEvent.MOUSE_DOWN)
{
switch(e.target.name)
{
case "titleBar":
e.target.root.parent.parent.startDrag();
break;

case "costIcon":
e.target.startDrag();
costIcon.removeEventListener(MouseEvent.CLICK, clickEvent);
break;
}
}

else if(e.type == MouseEvent.MOUSE_UP)
{
switch(e.target.name)
{
case "titleBar":
e.target.root.parent.parent.stopDrag();
break;

case "costIcon":
e.target.stopDrag();
costIcon.addEventListener(MouseEvent.CLICK, clickEvent);
break;
}
}
}

function redoWall(e:Event):void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
var scaleW = sw/wL.contentLoaderInfo.width;
var scaleH = sh/wL.contentLoaderInfo.height;
wL.scaleY = wL.scaleX = scaleW;
}

function addWall(e:Event):void
{
var scaleW:Number = stage.stageWidth/wL.contentLoaderInfo.width;
var scaleH:Number = stage.stageHeight/wL.contentLoaderInfo.height;
wL.scaleY = wL.scaleX = scaleW;
//wL.scaleX = scaleW;
stage.addChild(wL);

appIcon.x = 100;
appIcon.y = 100;
appIcon.scaleY = appIcon.scaleX = .8;
stage.addChild(appIcon);

lockIcon.x = 230;
lockIcon.y = 100;
lockIcon.scaleY = costIcon.scaleX = .8;
stage.addChild(lockIcon);

socialIcon.x = 100;
socialIcon.y = 300;
socialIcon.scaleY = socialIcon.scaleX = .8;
stage.addChild(socialIcon);

costIcon.x = 230;
costIcon.y = 300;
costIcon.scaleY = costIcon.scaleX = .8;
stage.addChild(costIcon);

performanceIcon.x = 320;
performanceIcon.y = 200;
performanceIcon.scaleY = performanceIcon.scaleX = .8;
stage.addChild(performanceIcon);
}

function addCost():void
{
if(!costHolder.showing)
{
stage.addChild(costHolder);
costHolder.x = stage.stageWidth / 4;
costHolder.y = stage.stageHeight / 4;
}
}

function addPerformance():void
{
if(!performanceHolder.showing)
{
stage.addChild(performanceHolder);
performanceHolder.x = stage.stageWidth / 4;
performanceHolder.y = stage.stageHeight / 4;
}
}

function addApp():void
{
if(!appHolder.showing)
{
stage.addChild(appHolder);
appHolder.x = stage.stageWidth / 4;
appHolder.y = stage.stageHeight / 4;
}
}

function addLock():void
{
if(!lockHolder.showing)
{
stage.addChild(lockHolder);
lockHolder.x =stage.stageWidth / 4;
lockHolder.y = stage.stageHeight / 4;
}
}

function addSocial():void
{
if(!socialHolder.showing)
{
stage.addChild(socialHolder);
socialHolder.x = stage.stageWidth / 4;
socialHolder.y = stage.stageHeight / 4;
}
}

function addListeners(e:Event):void
{
e.target.loader.content.close.addEventListener(MouseEvent.CLICK, clickEvent);
e.target.loader.content.minimize.addEventListener(MouseEvent.CLICK, clickEvent);
e.target.loader.content.titleBar.addEventListener(MouseEvent.MOUSE_DOWN, upDownEvent);
e.target.loader.content.titleBar.addEventListener(MouseEvent.MOUSE_UP, upDownEvent);
}

function removeLoader(l:Loader):void
{
l.alpha = 1;
if((Object(l.getChildAt(0)).minimize.minimized))
{
Object(l.getChildAt(0)).titleBar.transform.colorTransform = cf2;
Object(l.getChildAt(0)).title.transform.colorTransform = cf1;
TweenLite.to(Object(l.getChildAt(0)), .1, {scaleX:1, ease:Bounce.easeOut});
TweenLite.to(Object(l.getChildAt(0)).title, .1, { scaleX:1});
TweenLite.to(Object(l.getChildAt(0)).minimize, .1, {scaleX:1, x:"+10"});
TweenLite.to(Object(l.getChildAt(0)).close, .1, {scaleX:1});
TweenLite.to(Object(l.getChildAt(0)).clip, .1, {delay:.1,alpha:1});
Object(l.getChildAt(0)).minimize.minimized = false;
}
MovieClip(l.parent).showing = false;
stage.removeChild(l.parent);
}




One of the SWF’s of the Loaded Windows



import gs.TweenMax;
import gs.easing.*;

close.mouseChildren = false;
minimize.mouseChildren = false;
close.buttonMode = true;
minimize.buttonMode = true;

close.addEventListener(MouseEvent.CLICK, clickEvent);
minimize.addEventListener(MouseEvent.CLICK, clickEvent);

close.addEventListener(MouseEvent.ROLL_OVER, overEvent);
minimize.addEventListener(MouseEvent.ROLL_OVER, overEvent);

close.addEventListener(MouseEvent.ROLL_OUT, outEvent);
minimize.addEventListener(MouseEvent.ROLL_OUT, outEvent);

function clickEvent(e:MouseEvent):void
{
switch(e.target.name)
{
case "close":
trace("CLICK");
break;

case "minimize":
trace("MINIMIZE");
break;
}
}

function overEvent(e:MouseEvent):void
{
TweenMax.to(e.target, .7, {colorMatrixFilter:{colorize:0xFFFFFF, amount:1, brightness:1.2}, ease:Bounce.easeInOut});
}

function outEvent(e:MouseEvent):void
{
TweenMax.to(e.target, .7, {colorMatrixFilter:{colorize:0xFFFFFF, amount:0, brightness:1}, ease:Bounce.easeInOut});
}

Now On FlashDen

Yup, you read that right, I am now a developer on FlashDen. I know a lot of you are saying OH NOOOOO no more free stuff. On the contrary, I will still be releasing free content on the site as well as premium content on FlashDen. Most likely I will be releasing basic versions for free and more advanced versions with more features on FlashDen.



I hope everyone one supports me on this and keeps visiting the blog. First item I have up there is a more advanced version of the Fade In Gallery In this I have removed the link to this lass due to some bugs I have found in the class. So the only way to get this particular class is through FlashDen at this link

http://flashden.net/item/fade-in-gallery/20495

Everything else is still available. Again thanks for the support, and look out for more things in the future.

XMLLoader 2.0 Update***

I’ve been getting some complaints about the XMLLoader.

First I have to say I missed a file when packaging it for distribution. I have already fixed that and you can redownload to get the updated package.

Secondly, for people getting a host of errors and the Error message is “Loading Failed”. This is because you have cacheBuster set to true. The cacheBuster must be set to false when testing locally.

If any other bugs pop up, don’t hesitate to drop me a line. Thanks again for the feedback, this wouldn’t have been caught without your help.

Enjoy


Download XMLLoader Class 2.0 Here

Stable Release XMLLoader 2.0

**Update**
http://blog.kreativeking.com/2008/10/xmlloader-20-updatexmlloader-20-update/



I have been working hard on making this as robust and stable as possible. This release should be able to do anything you would like with loading XML. Couple of new features from 1.8 the community has been emailing me about as well as some that I wanted to include in past versions. I will be releasing a video tutorial on how to use this class properly. I’ll explain the new features to hold you over until then.





New Constructor



XMLLoader($url:Array = null, $cache:Boolean = false):void



In 2.0, the XMLLoader constructor now takes 2 parameters. The first, being the same as in past versions, an Array of the xml files being loaded. The second being a new feature called cacheBuster which I will get more into bit later. By default these are set to null and false respectively.



New Cachebuster Feature



XmlLoader 2.0 introduces the new Cachebuster feature. This feature allows you to always load up an up to date version of your XML File. This is will make it so your flash application will not used cached files. This parameter is takes a boolean value and can be set in two ways. One being in the constructor shown above. The second is by setting the cacheBuster property.



XMLLoader.cacheBuster = true;
XMLLoader.cacheBuster =false;



New way of referencing load XML’s



In past versions, to access a certain loaded XML file. Something like the code below would be used.



XMLLoader.getList["xmlfile.xml"];



In 2.0 the file extension is no longer accepted, just the name of the file like below.



XMLLoader.getList["xmlfile"];



Also in 2.0, if you have two loaded files that happen to have the same name. To access the other files after the first. You only need to put the name + underscore + array index. Here is an example.



var testXML:XMLLoader = new XMLLoader(["test.xml", "test2.xml", "test.xml", "test2.xml", "test.xml", "test2.xml"], true);
testXML.addEventListener(Event.COMPLETE, doIT);

function doIT(e:Event)
{
var list:XML;
list = testXML.getList["test_4"];
trace(list);
}



In the above code, the last test.xml will be loaded. The array index is its spot in the url array.



Those are the main new features in 2.0. Some other under the hood work includes some better error catching and proper event dispatching. The video tutorial should be out before the month is out as well as a new ite to host them, so look out for that. As always, let me know of any bugs and suggestions nd I will try to get to them ASAP.



Enjoy



Download XMLLoader Class 2.0 Here

More Information