Articles in the Code Samples Category
Code Samples, Flash, Tutorials »
I have an upcoming project that will require an mp3 player that can load multiple songs, and let users choose which track they would like to listen to. I created this as a test, and will be developing it further for use on the site itself.
The player loads in mp3′s from an external file based on xml settings.
Here’s the actionscript 3 that is involved:
var getMusic:URLRequest;
var music:Sound = new Sound();
var soundChannel:SoundChannel;
var currentSound:Sound = music;
var pos:Number;
var currentIndex:Number = 0;
var songPlaying:Boolean = false;
var xml:XML;
var songlist:XMLList;
//preloader
function loadProgress(event:ProgressEvent):void {
var percentLoaded:Number = …
Code Samples, Flash, SEO »
A very simple RSS feed reader that displays links off to your blog created using Actionscript 2.
stop();
//create the xml object
xmlLoad = new XML();
xmlLoad.load(_root.feed);
xmlLoad.ignoreWhite = true;
xmlLoad.onLoad = function(success){
//if successful
if(success && xmlLoad.status == 0){
//reset the text
xml_text="";
//list of items
var xmlItems:XML = xmlLoad.firstChild.firstChild;
for (var m = 0; m<xmlItems.childNodes.length; m++) {
//grab each item
if (xmlItems.childNodes[m].nodeName == "item") {
for (var n = 0; n<xmlItems.childNodes[m].childNodes.length; n++) {
if (xmlItems.childNodes[m].childNodes[n].nodeName == "link") {
//grab the link of the item
itemlink=xmlItems.childNodes[m].childNodes[n].firstChild.toString();
}
if (xmlItems.childNodes[m].childNodes[n].nodeName == "title") {
//grab the title of the item
itemtitle=xmlItems.childNodes[m].childNodes[n].firstChild.toString();
}
}
//add the current item
xml_text+= "<a href=\""+itemlink+"\">"+itemtitle+"</a><br><br>";
}
}
}
//set the text
xml_holder.text = xml_text;
}
The only library item needed …
Code Samples, SEO, Tutorials »
Inbound Links
A .htaccess file can be an SEO’s vital friend. When visitors hit your site with either www.yourdomain.com or yourdomain.com, it splits your inbound links into two separate pages. This can have effects on your Google Page Rank. By correctly creating and implementing a .htaccess file at your server root, you can improve your website ranking.
To change the url in the browser before the page loads you can use two different methods.
Here, the url will always contain the www. before the domain name:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.derekentringer\.com [NC]
RewriteRule (.*) http://www.derekentringer.com/$1 …
Code Samples, Flex, Tutorials »
Flex has a lot to offer when it comes to file manipulation and viewing/interaction. The AIR environment is perfect for an “explorer” type application.
Here’s a quick file browser in Flex:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1044" height="800" currentState="videoState" creationComplete="init()">
<mx:Style source="assets/css/styles.css" />
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.controls.Alert;
import flash.html.HTMLLoader;
import flash.net.URLRequest;
import mx.events.MenuEvent;
import mx.collections.*;
[Bindable]
public var menuBarCollection:XMLListCollection;
private var menubarXML:XMLList =
…
Code Samples, FMS, Flash, Tutorials »
This FLV player has quite a few advanced options included. The video is streamed from a Flash Media server, dynamically buffered, and playable. The server side scripts allow for dynamic port detection, and you can setup the player to serve differently encoded flv files based on the users bandwidth.
First let’s start with our external classes.
stop();
/*——————————————————————————–*/
//external classes
/*——————————————————————————–*/
import NCManager;
import mx.transitions.Tween;
We’re using the NCManager.as file as provided by Adobe. This external class allows us to manage our port connection list as well as detect a users bandwidth when they load our swf. I …
Code Samples, Flash, Tutorials »
Here I have all of the code necessary to setup a simple AS2 flv player using progressive download. All of this script is in the first frame of the movie with the appropriate movie clips available on the stage.
First, We setup all of our controls including our Play/Pause button, Rewind, Scrubbing, and volume controls.
stop();
/*——————————————————————————–*/
//sound settings/controls
/*——————————————————————————–*/
globalsound = new Sound();
globalsound.setVolume(100);
volume_slide.volume_slider._x = volume_slide.volume_bar._width-volume_slide.volume_slider._width;
b_volume.onRelease = function() {
if(globalsound.getVolume() == 100){
b_volume.gotoAndStop(2);
globalsound.setVolume(0);
}else if(globalsound.getVolume() == 0){
b_volume.gotoAndStop(1);
globalsound.setVolume(100);
}
}
//volume scrubbing
var pTop_volume:Number = volume_slide.volume_slider._y;
var pLeft_volume:Number = 0;
var pBottom_volume:Number = volume_slide.volume_slider._y;
var pRight_volume:Number = volume_slide.volume_bar._width-volume_slide.volume_slider._width;
volume_slide.volume_slider.onPress = function() {
startDrag("volume_slide.volume_slider", false, pLeft_volume, pTop_volume, pRight_volume, pBottom_volume);
dragging = …
Code Samples, FMS, Flash, Tutorials »
Here’s a quick way to setup a Flash Media Server chat room. This process only allows for two users to video chat over Flash Media Server, and was the start of a larger project that I was involved with.
Setting Up the Flash Media Server Application
It really what you are going to use in terms of either a FMS hosting company, or your own. Most of the FMS hosting companies use the same techniques when setting up their servers for users, but that might not always be true. In general, you …
Code Samples, Flash, Tutorials »
Here’s a class that renders a simple wireframe sphere in Papervision3d, and allows the mouse to control the pitch and yaw. This example can be applied to any simple interactive environment.
package {
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.scenes.*;
import org.papervision3d.materials.*;
public class PaperVisionTest extends Sprite {
/** setup the container */
private var container: Sprite = new Sprite();
/** setup the scene */
private var scene: MovieScene3D = new MovieScene3D(container);
/** setup the camera */
private var camera: Camera3D = new Camera3D();
/** setup the material */
private var material:WireframeMaterial = new WireframeMaterial(0xFF0000);
/** setup the sphere */
private var sphere:Sphere = new …
Code Samples, Flash, Tutorials »
Here’s a simple scene that renders a Papervision3d scene within a container. There are no 3d elements added, but this is as simple as it gets.
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
import org.papervision3d.scenes.*;
var container:Sprite = new Sprite();
addChild(container);
container.x = stage.stageWidth * 0.5;
container.y = stage.stageHeight * 0.5;
var scene:Scene3D = new Scene3D(container);
var camera:Camera3D = new Camera3D();
camera.zoom = 11;
addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event):void
{
scene.renderCamera(camera);
}
If you’re interested in how this can be improved, check out the next post with a more elaborate Papervision scene.
Code Samples, Flash »
Re-usable class created by brianConnatser that will set up an external XML feed to use E4X, datagrids, and much more.
Check out some of the code





