Monday, September 17, 2007

Titlebar 3.0

HA!

Finally updated the titlebar of this blog to Actionscript 3.0!

New stuff that I changed:

  • It's in Actionscript 3.0!
  • It's easier for me to change the song now
  • The SWF reads the MP3's ID3 tag (LOL) for the artist and title
  • The SWF also tracks the song's left and right amplitudes during runtime
  • Because of the above, my barcode animation is divided into two and they move independently
Here's the code. It won't work if you just paste this flash by itself because I also have the movieclips on the stage. This is just for reference on how to use the different new soundChannel class properties. I just placed this code on the first frame of the timeline in an actions layer:

import caurina.transitions.Tweener; import flash.events.*; import flash.net.*; import flash.media.*; import flash.display.*; Tweener.init(stage); //XML stuff var myXML:XML = new XML(); myXML.ignoreWhitespace = false; var XML_URL:String = "http://www.designbylaw.net/blog/stuff.xml"; var myXMLURL:URLRequest = new URLRequest(XML_URL); var dataLoader:URLLoader = new URLLoader(myXMLURL); dataLoader.addEventListener("complete", xmlLoaded); //initials Tweener.addTween(bars, {alpha:1, time:6, transition:"easeOutExpo"}); longTxt.text = 11010199091001; shortTxt.text =1010; //xml..load function xmlLoaded(evtObj:Event){ myXML = XML(dataLoader.data); var numOfItems:Number = myXML.element.length() - 1; var rand:Number = Math.ceil(Math.random()*numOfItems); quotes.text = myXML.element[rand].@word; } //home theTitle.buttonMode = true; theTitle.addEventListener(MouseEvent.CLICK, goHome); function goHome(e:Event){ navigateToURL(new URLRequest("http://www.designbylaw.net/blog"),"_self"); } //hit hit.buttonMode = true; hit.addEventListener(MouseEvent.MOUSE_OVER,hitOver); hit.addEventListener(MouseEvent.MOUSE_OUT,hitOut); hit.addEventListener(MouseEvent.CLICK,hitPlay); function hitOver(e:Event){ Tweener.addTween(bars, {scaleY:0.1, time:1, transition:"easeOutExpo"}); } function hitOut(e:Event){ Tweener.addTween(bars, {scaleY:1, time:1, transition:"easeOutExpo"}); } function hitPlay(e:Event){ var soundUrl:String = "http://www.designbylaw.net/blog/MySound.mp3"; var soundFactory:Sound = new Sound; var channel:SoundChannel; var theEnterFrame:Timer; playHit.visible = false; hit.visible = false; soundFactory.load(new URLRequest(soundUrl)); soundFactory.addEventListener(Event.ID3, id3Handler); function id3Handler(e:Event){ quotes.text = soundFactory.id3.artist + " - " + soundFactory.id3.songName; } channel = soundFactory.play(); theEnterFrame = new Timer(50); theEnterFrame.addEventListener(TimerEvent.TIMER, perMoment); theEnterFrame.start(); function perMoment(te:TimerEvent){ bars.barsLeft.scaleY = channel.leftPeak; bars.barsRight.scaleY = channel.rightPeak; longTxt.text = Math.round(channel.position/120) + 11010199091001; shortTxt.text = 1010 + Math.round(channel.position/1200); } channel.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); function soundCompleteHandler(e:Event){ bars.barsLeft.scaleY = 1; bars.barsRight.scaleY = 1; bars.scaleY = 0; Tweener.addTween(bars, {scaleY:1, time:1, transition:"easeOutBounce"}); playHit.visible = true; hit.visible = true; quotes.text = "Thanks for Listening"; theEnterFrame.stop(); } } //right-click var theMenu:ContextMenu = new ContextMenu(); theMenu.hideBuiltInItems(); var theCopy:ContextMenuItem = new ContextMenuItem("designbylaw",true); theMenu.customItems.push(theCopy); this.contextMenu = theMenu; theCopy.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, goToSite); function goToSite(e:Event){ navigateToURL(new URLRequest("http://www.designbylaw.net/"), "_blank"); }

...if anyone cares.

4 Comments:

Blogger kaz said...

Nice! Keep it going. I need a venue for posting these stuff too...

9/17/2007 8:19 PM  
Blogger Vee said...

totally geekin' out.
=)

the music is greeeaatttt.

9/18/2007 4:04 PM  
Blogger Ding said...

i like the music player and the music. i want to make one for my blog, but i don't have time.

9/21/2007 12:55 AM  
Blogger Ivan L said...

nice. love the music, too. are you allowed to do that, though?

10/08/2007 11:18 AM  

Post a Comment

<< home ||Close