Friday, February 4, 2011

Video Player

Since I never handled FLV video in actionscript before, I referred to the script in this tutorial:
http://www.thetechlabs.com/tech-tutorials/audionvideo/how-to-build-a-as3-videoplayer/
However the video player that I need does not require the play/stop button, the volume scrubber and the timer display, so I removed the following lines

var bolVolumeScrub:Boolean = false;
function playClicked(e:MouseEvent):void { ... }
function pauseClicked(e:MouseEvent):void { ... }
function stopClicked(e:MouseEvent):void { ... }
function volumeScrubberClicked(e:MouseEvent):void { ... }
function formatTime(t:int):String { ... }


and some nested lines in updateDisplay and mouseReleased methods.
The submitted final had some bugs though, you can see it in the uploaded version here when you seek for the parts which hasn't been streamed yet. I should have written a progress handling function for it. Other than that, I intended to use TweenMax to slowly fade out the background music instead of just mute it, however it failed and the script did not work very well. Further improvement will be made soon.

Wednesday, February 2, 2011

Plugins

When I was learning scripting in the secondary school time, I liked to write everything from scratch, and I kind of discriminate people who copies scripts from the others. However from time to time I started to understand the difference between learning and production.

While learning, what's important is the process, but when involved in production, what's important is the speed and the outcome.

Thus, most of the programming masters in the industry are not using 100% genuine codes, except when they are writing codes for security. Script libraries such as JQuery are widely used as a "shortcut" to make things done faster. Followings are the coding plug-ins that I used throughout the production of the website, in both PHP and Actionscript:


1. PHP MySQL wrapper:
MySQL requests are used very frequently when writing PHP codes, that means you would need to type the same thing over and over again in every PHP files. To make it easier, faster and less complicated, it's best to write a class that handles all the database connections.. PHP MySQL Wrapper written by ricocheting is what I've found very useful.
http://www.ricocheting.com/code/php/mysql-database-class-wrapper


2. TweenMax
TweenMax is a plug-in that shorten a lot of codes for animation. For instance, if you want to move a box from 0 to 100 in 25 frames, you need to write the following codes (hard-coding):
function move():void {
addEventListener(Event.ENTER_FRAME, step);
}

function step(e:Event):void {
      x+=4;
      if( x >= 100 ) {
            x = 100;
            removeEventListener(Event.ENTER_FRAME, step);
      }
}

in TweenMax, you just need to write this line:
TweenMax.to(this, 1, {x:100});
and everything is done for you!! you can even assign easing function to make it bounce, going back or appearing elastic.
http://www.greensock.com/tweenmax/


3. AES
AES is a cryptography method used in military force. In Flash-PHP integration, it's used to prevent hacking. In the contest part, I've implemented AES so that people could not simply hack the contest results with SQL-injection method.
http://www.lostinactionscript.com/blog/index.php/2009/11/29/aes-cryptography-for-actionscript-php/

Software

When typing codes in actionscript using Object-Oriented Programming, you need to declare a "class" for every object that needs scripting, and for every function you use in a single class, you need to write a line that imports that functionality to your class in order to work, and that would be a headache if you're just typing in Adobe Flash itself because it doesn't have any automation, for example, these lines:

package nutrigen {
      import flash.display.Sprite;
      import flash.events.Event;

      public class Frame extends Sprite {
            public function Frame ():void {
                  if (stage) init ();
                  else addEventListener(Event.ADDED_TO_STAGE, init);
            }

            private function init (e:Event = null):void {
                  removeEventListener(Event.ADDED_TO_STAGE, init);
            }
      }
}


this is how a class look like, and it is sort of the framework code that we need to type in every single ".as" file. thus, a better software, which is specially made for actionscript coding, is used:

the FlashDevelop!

i guess it saved me more than 24 hours throughout this project :D
it generates the framework code, and writing the "import" codes automatically for me, and generates functions whenever i needed.. basically it's a must-have for every actionscript coder..

highly recommended by Darien Toh, a senior actionscript coder in If Interactive, 1 of my sifu xD