Showing posts with label flash. Show all posts
Showing posts with label flash. Show all posts

Tuesday, December 04, 2007

Creating the time rag using Tween.

People put cool intro type effect all the time but one of them that i was dying to do through actionscript was time rag. i mean if you look at http://www.2advanced.com for example you can see stuff at the bottom coming in at different timing.

well i finally found out how to do this with action script. i guess it can be done just by animating manually but usually for these kind of thing it's way faster and more acurate to do it via ActionScript.


var speed:Number = .5 * i+1;
var xTween:Tween = new Tween(pp, "x", Back.easeOut, -300, 30, speed, true);
xTween.start();

if you look carefully into it you see a variable i

well yes this is inside the for loop. and iterates for how ever many movie clips that's inside of an array. i was doing this for my new photo gallery i was building.

Here i'm giving a variable speed 0.5 * i + 1
0.5 * i expresses difference in time.
+ 1 is basically an offset value so that the element 0 or the first one will still show up. (0 * anything is 0 so speed or time it takes will be 0 - in Tween class term it means do nothing)

so putting all elements that you want time rags when showing up in an array and create for loop and tween all of them with a bit different speed.

well if you are going to do this for 100 elements it might not work...


I'm still searching for a way to do real time rag which just keeps pause before triggering animation..

maybe if you use eventListever for MOTION_FINISH and 2 tweens it will.

Saturday, December 01, 2007

Dynamic Text Embed Font ActionScript 3.0 tips

this is another ActionScript 3.0 or Flash CS 3 tips.

What really stopped me from creating contents today was the dynamic text.. it is an amazing thing but this thing drove me crazy.

i basically had one button that is associated with a class and on rollover, rollout, click, etc tween starts so that it will animate according to an MouseEvent.

Problem I had was i was trying to tween alpha and it didn't kick in. trace shows that it's changing alpha.. i checked my tween also by trying the same tween with other properties like x and it totally works...

i had another regular button that doesn't associate with this button class and that one also was working fine.

only the one i have created through class... didn't do alpha tweens.. (just that didn't show result on screen...)

I really tried bunch of things like loading them into another MovieClip and applying tween to that MovieClip etc...

Then i went to check the differences between the buttons that does alpha tweens and don't.. i noticed one slight difference..
The one that worked had static text for labels and the one that didn't work had dynamic text.

so i went to research "dynamic text alpha" well Bingo.

in order to apply alpha tween to an dynamic text you need to Embed and font.

well first didn't make sense at all but i looked into property inspector for the text and on the right hand side i saw "Embed.." button. and ah huh! i clicked on the button and set it up.

Command + Enter to test movie and it works!!! now i can tween dynamic texts.

if you choose both all upper case and all lower case letters, you should be able to change label dynamically. and now i have a button that plays fancy animation. not like and HTML/CSS simple roll over but a button that does something and that's totally customizable. great.

took me too long to figure out this simple things but i'm sure you won't need to.

Thursday, November 29, 2007

Controlling sound in Flash CS 3 or ActionScript 3.0

I was trying to make an audio player for a web site in flash cs 3 or actionscript 3.0 today and it was more than confusing..

i was reading the references and took me a while before i realized that you had to have bunch of other objects to perform tasks like stopping,..

yes.. stopping sound seems easy but not really in actionscript 3.0..but once you get it you won't forget it.

to make an audio or mp3 player in as3 you need three objects.

Sound() - for loading sounds
SoundChannel() - to control playback, stopping
SoundTransform() - to control volume and panning(Left, right stereo stuff)

SoundChannel has .soundTransfor where you can assign SoundTransform() object


var sound:Sound = new Sound();
var sControl:SoundChannel = new SoundChannel();
var vControl:SoundTransform = new SoundTransform();


so now you have 3 objects. let take a look at how they interrelate


sound.load(new URLRequest("yourSong.mp3"); // get the sound clip
sound.addEventListener(Event.COMPLETE, soundLoaded); // triggers a function soundLoaded on load complete
btnStop.addEventListener(MouseEvent.CLICK, stopSound); // create button with inst name of btnStop on stage for it to work
btnVolumeUp.addEventListener(MouseEvent.CLICK, changeVolume);

function soundLoaded(e:Event):void
{
sControl = sound.play(); // this is the hard part...
}

function stopSound(e:MouseEvent):void
{
sControl.stop(); // sound.stop() won't work for some reason.. or for a good reason..
}

function changeVolume(e:MouseEvent):void
{
vControl.volume += .1; // since volume property's range is 0 to 1
sControl.soundTransform = vControl; // assign that info to control
}


well this should blow up your speaker since it only goes up. try it at your own risk and i didn't tell you to do it. so you can't sue me. you should spend your time in other things like try implementing decreasing volume or much more flexible way of controling volume, etc.

Friday, August 31, 2007

Document Class - Flash ActionScript 3.0 feature

Now you can assign class to a document...

you just define a class, and inside the property window for the document, you should see a text field saying "Document Class"

type in ULR or name for your document class (anything..) and you are good to go.

you can actionscriptically load graphics, etc pretty easily. amazing feature

Tuesday, June 26, 2007

ActionScript 3 Timer class

interesting thing i've descovered..
you are adding listener to the timer

Now i think that's a logical choice but for a while i was thinking that i had to tell object to listen to the timer...

well so here is my preloader test code with timer class.



import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.utils.Timer;

var velocity:Number = 1;
var loadProgress_txt:TextField = new TextField();
var siteLoader:Loader = new Loader();
var myFog1:URLRequest = new URLRequest("Source/images/Fog2.png");
var myTrigger:Timer = new Timer(2000, 20);

// initialize
siteLoader.load(myFog1);
siteLoader.alpha = 0.5;
siteLoader.x = 0;
siteLoader.y = 0;

loadProgress_txt.x = 200;
loadProgress_txt.y = 200;
loadProgress_txt.autoSize = TextFieldAutoSize.LEFT;

// add listeners
siteLoader.contentLoaderInfo.addEventListener(Event.OPEN, showPreloader);
siteLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
siteLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, showLoadResult);




function showPreloader(evt:Event):void {
addChild(loadProgress_txt);
}

function showProgress(evt:ProgressEvent):void {
loadProgress_txt.text = "loaded:"+evt.bytesLoaded+" from "+evt.bytesTotal;
}

function showLoadResult(evt:Event):void {
removeChild(loadProgress_txt);
addChild(siteLoader);
myTrigger.start();
myTrigger.addEventListener(TimerEvent.TIMER, loadAnother);
}

function loadAnother(evt:TimerEvent) {
siteLoader.x -= velocity * 10;
}



not really a pretty one yet but i can build on this to make a pretty one. using timer was easy too.

Different rounding methods in ActionScript

Math.round - rounds up or down
- 4.4 will be 4, 4.6 will be 5
- if you

Math.round(Math.random() * 10)

you will get numbers from 0 to 10 - total 11 numbers.

Math.floor - rounds DOWN to floor
- 4.4, 4.6, 4.9999 will all be 4
- if you

Math.floor(Math.random() * 10)

you won't get 10. Numbers you get will be between 0 and 9. total 10 numbers.



Math.ceil - rounds UP to ceiling
4.001, 4.4, 4.6 will all be 5
- if you

Math.floor(Math.random() * 10)

you won't get 0. Numbers you get will be between 1 and 10. total 10 numbers.



likewise ceil and floor can be used depending on what you need.
you won't have to do annoying + 1 after the generating a random number, if you know what i mean. - if not just remember what's stated above and you should be good to go.

Sunday, December 10, 2006

flash game tutorial from strille.net - modulo %

i was just reading this tutorial from strille.net on flash and this is really interesting...

i've been trying to hone my skill on multimedia programming so i'm just looking into game codes.
structure wise they all share similar routes. but what's in there or the codes people use to achieve certain results are interesting.

like.. % modulo
for a beginner like myself. when you learn about modulo it's like what? how do you even try to use that? but for this kind of application this works really well and i was amazed how much if else you can avoid just with these simple steps.



How to make Snake Game with Flash Tutorial