Monday, February 15, 2010

Icons for List Component


So I’ve gotten a few questions about how to place custom icons in the List component, like the ones on the gotoAndLearn() site. So here is the code block that I use. The instance name of my List component is “tl” in this case:
[as]tl.iconFunction = function(item) {
if(item.data.indexOf(“aftereffects”)!=-1) return “ae”;
if(item.data.indexOf(“flash”)!=-1) return “flashIcon”;
if(item.data.indexOf(“swift”)!=-1) return “swiftIcon”;
if(item.data.indexOf(“photoshop”)!=-1) return “photoshopIcon”;
}[/as]

The List component has an event called “iconFunction” that you will need to set up. It is called when the List is instantiated and it calls it for every item in the list. Each time it sends the item and you need to define a parameter to catch it. I used “item” in the above example. Then you simply do some checking to determine what icon is appropriate for that item, and return it. In the above code you will see that I have four different icon MovieClips in my library called “ae”, “flashIcon”, “swiftIcon”, and “photoshopIcon.” Make sure to set up the linkage ID for your MovieClips.
But lets say that you only need one icon for all of the items in the list. Then your “iconFunction” definition would look like:
[as]tl.iconFunction = function(item) {
return “yourIconMovieClip”;
}[/as]

Monday, February 1, 2010

Flash Timecode Class


I’ve written a Timecode class that will take the ns.time property and return a timecode string in the “00:00″ format. See below for how it is used.
[as]var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
thevideo.attachVideo(ns);
ns.play(“yourFLV.flv”);
var tc:Timecode = new Timecode(ns);
this.onEnterFrame = function() {
trace(tc.getTimecode());
}[/as]

There is also a “setDelimiter()” method available if you want change the colon to some other character.
tc.setDelimiter(“|”);

XML Video Playlist


I’ve been lagging a bit lately with getting new tutorials up. My “real” job has been keeping me pretty busy. But I will be uploading a new tutorial later today which will show how to make an XML-driven video playlist. I’ve gotten tons of requests for this tutorial so I hope that you find it helpful.
It should be up on gotoAndLearn() by about 6:00 pm California time.

Got Timecode?

Here is a simple function that takes the ns.time value and turns it into a timecode string. This would actually make a good class.
[as]function getTimecode(theTime:Number):String {
var t:Number = Math.round(theTime);
var min:Number = Math.floor(t/60);
var sec:Number = t%60;
var s:String = “”;
if(min < 10) {
s += "0";
}
if(min >= 1) {
s += min.toString();
}
else {
s += “0″;
}
if(sec < 10) {
s += “0″;
s += sec.toString();
}
else {
s += sec.toString();
}
return s;
}[/as]

Free FLV Component

I just created version 1.0 of my FLV player component. Its 100% free of course. Check back often for updates to it as its pretty bare bones right now. You can only view FLV files that are 320×240 and there is no scrubber. Besides that its fully functional. I will be adding these features very soon though. Below are the steps on how to use it:
  1. Download the component and install using Extension Manager.
  2. Drag the component from the components panel to the stage.
  3. Place the component on a whole number for its X and Y values.
  4. In the component inspector you can customize the load bar and progress bar colors.
  5. Lastly, enter the URL of your FLV file.
  6. Enjoy your video :-)

Video Scrubber Modified


[as]this.createEmptyMovieClip(“vFrame”,this.getNextHighestDepth());

vFrame.onEnterFrame = videoStatus;
var amountLoaded:Number;
var duration:Number;
ns["onMetaData"] = function(obj) {
duration = obj.duration;
}
function videoStatus() {
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loader.loadbar._width = amountLoaded * 208.9;
loader.scrub._x = ns.time / duration * 208.9;
}
loader.scrub.onPress = function() {
vFrame.onEnterFrame = scrubit;
this.startDrag(false,0,this._y,208,this._y);
}
loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
vFrame.onEnterFrame = videoStatus;
this.stopDrag();
}
function scrubit() {
ns.seek(Math.floor((loader.scrub._x/208)*duration));
}[/as]