Posts Tagged ‘com.dyc (Classes)’

Using external classes in Actionscript 3


Wednesday, October 21st, 2009

FlashExternal classes are a great way to get lots of advanced functionality in your applications, without having to write custom code. This may seem simple to most of you, but I remember when I was just starting out in Actionscript 3, and I could’ve used an article on this.

There is a huge collection of classes available online for free, a few of which live here on my site! You can probably find a class to do nearly anything pretty easily. There are classes that tween properties, play videos, mp3’s and all kinds of other stuff.

One of my favorite classes is TweenLite, which is a very tiny tweening class. Some other good ones include Papervision3D, Adobe’s Libraries, the Google API’s and as3DMod.

Using your first class

If you’ve never used an external class before, it can seem a bit confusing. Don’t worry, its so simple, and extremely useful! Let’s go through an example, using my com.dyc.video.VideoPlayer class. All of that com.dyc stuff is nothing to be confused about. It is merely the folder structure that organizes the classes. When you download my VideoPlayer class, it will unzip to a folder called com, which has a folder inside of it called dyc, and so on, until you hit a file called VideoPlayer.as, which is the actual class file.

Drop the com folder in the same folder as the FLA (or flex source) you want to use the VideoPlayer on. First thing you need to do is import the class. At the very top of your DocumentClass (or other class file where you’ll be using the imported class), you start with the import statement:

import com.dyc.video.VideoPlayer;

This loads the Actionscript class into memory. To use a class, you normally have to create an instance of it. You can do this by declaring a variable, and giving it a type of VideoPlayer(or whatever class you are importing).

var videoPlayer:VideoPlayer;

Now you have somewhere to access the class from. If the class contains a display item, something that will be shown in flash, you will probably want to set the x and y coordinates of the class, then addChild() to put it on the stage. You will also have to instantiate the class(unless its a Singleton class, but more on that in a later post). To instanciate, you merely create a new instance of the class, through the variable you just created.

videoPlayer = new VideoPlayer(320, 240, videoURL);

Sometimes a class has the ability to pass variables to the constructor. This sets up the class with your specific data. In the previous snip of code, we passed 3 variables to the new VideoPlayer() instnace. The first two are the width and height of the video player and the third is a variable that points to a URL of an FLV.

If you wanted to run a function called togglePause() on the VideoPlayer, you would access it through the instance you made.

videoPlayer.togglePause();

That is basically it. You can read through the documents of any classes you download, or read through the class itself to find out how to use it. Most classes have very good documentation, so they’re very easy to figure out.

com.dyc.photo.Slideshow


Friday, October 2nd, 2009

FlashIt doesn’t get any easier than this. Need to make a quick slideshow? This is all you need (Plus the Tweener class, which needs to be installed in the same directory as your source FLA).

Download it here!

Here is another easy to copy example on how to use this bad boy:

import com.dyc.photo.Slideshow;

// Pick some photos to go through
var tempPhotoURL1:String = "http://tinyurl.com/ydy48zj"
var tempPhotoURL2:String = "http://tinyurl.com/y8w5p9g"

var photosListArray:Array = [tempPhotoURL1, tempPhotoURL2];

var my_slideshow:Slideshow = new Slideshow(4, 4,  photosListArray, "easeOutExpo");
addChild(my_slideshow);

/*
Other functions you can call on this:

my_slideshow.pause();
my_slideshow.resume();
*/

It’s pretty straight forward, you just import the class, create a new Slideshow object, and pass your setup variables to the newly created object.

The following arguments are accepted:

  • photo_display_time:int
  • fade_time:int
  • photoURLs:Array
  • easing:String

You can addChild() this to a masked off MovieClip or Sprite, to make it fit in with your particular design. For the easing:String parameter, you can pass any of Robert Penner’s Easing Types.

Let me know if you have any trouble with it, shouldn’t be too many places this can break down ;D

com.dyc.video.VideoPlayer


Thursday, September 24th, 2009

FlashVideoPlayer is an Actionscript 3.0 class that does what its called. Play’s videos!

It’s easy to use, and will quicken up your video player build time!

Download It Here.

Here is an example of how to use it (included in the download too):

import com.dyc.video.VideoPlayer;

var tempVidURL:String = 'http://tiny.cc/P85VM';

var videoPlayer:VideoPlayer = new VideoPlayer(320, 240, tempVidURL, true);
videoPlayer.x = 10;
videoPlayer.y = 10;

addChild(videoPlayer);

/*
Functions you can call on the video player!
Use these to make it work with your controls

videoPlayer.togglePause();
videoPlayer.playVideo('video.flv');
videoPlayer.resizeVideo(300, 240);
videoPlayer.setVolume(0);
*/

The next release should include playlist support, animated re-size, and a few other fun things!

I have a few other classes in the works, and I will be tossing them up here when they are done. Just some little things that make it easy to skip the grunt work and focus on the project! Eventually, I want to put it all into a nice big package to distribute together.

If you have any suggestions, leave a comment or shoot me an email!

Enjoy!