Tag Archives: Javascript

Get your Dojo working

Tonight’s Twin Cities Web Design user group meeting here at The Nerdery features Dojo guru Chris Barber of CB1, Inc. Chris will do a show-and-tell on how he uses the Dojo JavaScript toolkit to build rich apps. He’ll cover: manipulating the DOM; event handling; cross-browser quirks; widgets; and the build system.

What: Dojo – JavaScript’s Swiss Army Knife

When: Wednesday, July 15, 6-8 p.m.

Where: The Nerdery

We’re pleased to host this user group, and all the more pleased when we know who’s coming (so we can order enough pizza), so please leave a comment on the TC Web Design website if you’re Nerdery bound (resident nerds, same goes if you’re staying).

Filed under Design, Events, Technology

Good evening, jQuery

Tomorrow at 6 p.m., The Nerdery welcomes jQuery expert Marc Grabanski to lead a Twin Cities Web Design user group discussion on jQuery essentials.

Marc Grabanski is the original author of jQuery UI Datepicker and has worked extensively with jQuery since the release of the fast, lightweight and concise JavaScript library.

A snippet from the library? Check this out:

<script type=”text/javascript” src=”/path/to/jQuery.js”></script>

I could read between the lines of this stuff for-like-ever. Where’s my jQuery library card?

Mark Grabanski will better address how the open source JavaScript library simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development – and how he uses jQuery as a Minneapolis-based web developer who consults with businesses creating startups.

When: Wednesday, June 24, 2009 6-8 p.m.
Where: The Nerdery, 9555 James Ave S. suite 245, Bloomington MN

The Twin Cities Web Design user group is a community for Minnesota-based web designers, developers and anybody interested in learning or developing their skills in the web marketplace.

Get more info and RSVP.

Filed under Uncategorized

Tech Tuesday — YouTube in AIR

The YouTube video player is currently written in ActionScript 2.0 and integrating it into an AIR application requires a few additional steps. There are many solutions available that reverse engineer the URL to get access to the source video FLV, however, this breaks the terms of service and is not officially supported by YouTube or the API.

By taking advantage of the HTMLLoader class we are able to load the YouTube Chromeless video player into AIR without breaking the terms of service. It essentially loads up a web page within the AIR application and uses JavaScript to control the video.

Lets start by creating the JavaScript / HTML portion of the application that the HTMLLoader will consume. Resources for this can be found here; YouTube Chromeless Player Example page.

Simplified JavaScript functions for this example (includes Play, Pause and Load):

JavaScript:
  1. <script src="js/swfobject.js" type="text/javascript" />
  2. <script type="text/javascript">
  3.  
  4.       function onYouTubePlayerReady(playerId) {
  5.         ytplayer = document.getElementById("myytplayer");
  6.       }
  7.    
  8.       // functions for the api calls
  9.       function loadNewVideo(id, startSeconds) {
  10.        if (ytplayer) {
  11.          ytplayer.loadVideoById(id, startSeconds);
  12.         }
  13.        }
  14.      
  15.        function play() {
  16.           if (ytplayer) {
  17.             ytplayer.playVideo();
  18.           }
  19.         }
  20.  
  21.        function pause() {
  22.          if (ytplayer) {
  23.            ytplayer.pauseVideo();
  24.          }
  25.         }
  26.  
  27.   </script>

Next we will use the SWFObject to load in the YouTube Chromeless video player. Notice the use of wmode: "opaque" in this example. Without this you will not be able to place any display objects above your videos.

JavaScript:
  1. <script type="text/javascript">
  2.  
  3.        // allowScriptAccess must be set to allow the Javascript from one
  4.        // domain to access the swf on the youtube domain
  5.        var params = { allowScriptAccess: "always", bgcolor: "#cccccc", wmode: "opaque" };
  6.        // this sets the id of the object or embed tag to 'myytplayer'.
  7.        // You then use this id to access the swf and make calls to the player's API
  8.        var atts = { id: "myytplayer" };
  9.        swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer",
  10.                            "ytapiplayer", "400", "300", "8", null, null, params, atts);
  11.  
  12. </script>

ActionScript Used to Load and Control the Video:

Actionscript:
  1. package com.sb.util
  2. {
  3.    import flash.display.Sprite;
  4.    import flash.events.Event;
  5.    import flash.html.HTMLLoader;
  6.    import flash.net.URLRequest;
  7.          
  8.    public class JSVideoPlayer extends Sprite
  9.    {
  10.  
  11.          private var _html:HTMLLoader;
  12.          private var _ready:Boolean = false;         
  13.        
  14.          public function JSVideoPlayer()
  15.            {
  16.              _html = new HTMLLoader();
  17.              _html.paintsDefaultBackground = false;
  18.              _html.width = 400;
  19.              _html.height = 300;
  20.              _html.addEventListener(Event.COMPLETE,
  21.                                     onComplete);
  22.                
  23.              loadHTMLcontent() 
  24.  
  25.              this.addChild( _html );
  26.          }
  27.          public function loadNewVideo(videoID:String):void
  28.          {
  29.               if(_ready){
  30.                  _html.window.loadNewVideo(videoID);
  31.               }
  32.          }
  33.          
  34.          public function playVideo():void
  35.          {
  36.                if(_ready){
  37.                   _html.window.play();
  38.                }
  39.          }
  40.    
  41.          public function pauseVideo():void
  42.         {
  43.              if(_ready){
  44.                 _html.window.pause();
  45.              }
  46.         }
  47.            
  48.         private function onComplete (e:Event):void
  49.         {
  50.              _ready = true;
  51.         }
  52.              
  53.         public function loadHTMLcontent():void
  54.         {
  55.              _html.load(new URLRequest('test.html'));
  56.         }
  57.  
  58.    }
  59. }

One of the limitations of using the HTMLLoader class is the inability to set the opacity of the video. For example you if wanted to fade the video out you would have to capture the current state of the video and replace it with a bitmap image that would then be faded out (download the zip file to see an example of this).

Source Files (ZIP)

Sources

PS: This example is only for AIR and may not work for Flex applications deployed on websites. Please visit 'YouTube in Flex applications' (On The Other Hand) for an example of how to do this in Flex.

This was originally posted on blackcj.com, Chris Black's personal blog. Chris is a Senior Developer at Sierra Bravo.

Filed under Technology

Profiles in Nerdery: Jansen Price, maker of computer programs and snack expert

  1. Astrological Sign: Astrology is garbage. But if you want to know my birthday, it's February 28th.
  2. Time at the Nerdery: 33,399,512 seconds. (At the time of this writing).
  3. Area of expertise: PHP, XHTML, Javascript, Production Design, Snacks.
  4. When people ask you what you do, how do you respond: I get to make computer programs for a company that makes awesome web sites and applications.
  5. Favorite kinds of projects to work on: Projects with clearly defined requirements, custom interfaces, or plenty of time for testing/bug-fixing.
  6. What one thing about The Nerdery surprises people the most when you tell them about it: Nothing. I don't tell anyone anything about the Nerdery. It's a secret! Shhhhhh.
  7. Seven dream Jeopardy Categories: 1. Vim keyboard shortcuts; 2. Capitals of the world; 3. Star Trek: TNG Episodes; 4. The Metric System; 5. Songs by the band Nirvana; 6. Things I like to do; and 7. Things to do when you're bored. Honestly, I am not very good at Jeopardy... it seems so backwards to me.
  8. Favorite Fictional Nerd: George McFly. He just seems like a guy I could be friends with.
  9. According to the Wikipedia entry on Nerd, some nerds show a pronounced interest in subjects which others tend to find dull or complex and difficult to comprehend, or overly mature for their age, especially topics related to science, disambiguation, mathematics and technology. Do you know what disambiguation is: Yes, I do.