Noob Flash
Digital Creation News & Tutorials


JavaScript Image Rotator

April 5th, 2009 by Matthew Hancock, Filed under - HTML ~ JavaScript
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

I created this JavaScript image rotator to solve a problem a client of mine was having on their site last week.

The first step is to create an empty div that the images can be loaded into. The easiest way to access a specific div from JavaScript is to make sure the div has an id, and access the div by referencing the div id as such:

var bannerHolder = document.getElementById('bannerHolder');

Once you have created the div and have a way to reference it via JavaScript, you will need to create an array of image urls to loop through.

var bannerArray = new Array();
var currentImage = 0;
bannerArray = ['http://www.noobflash.com/wp-content/themes/LemonPress/images/JavaScriptImageRotator/google.jpg','http://www.noobflash.com/wp-content/themes/LemonPress/images/JavaScriptImageRotator/yahoo.jpg','http://www.noobflash.com/wp-content/themes/LemonPress/images/JavaScriptImageRotator/msn.jpg'];

Tie these pieces of code together using setInterval to create the timed rotation and you have your image rotator. Get the complete code using the link below:

Get Complete Code

Add Comments |  Subscribe to NoobFlash

Basic JavaScript Array Tutorial

March 10th, 2009 by Matthew Hancock, Filed under - ActionScript ~ JavaScript ~ Tutorials
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

If you have ever created an array in ActionScript or any other ECMAScript based programming language, creating an Array in JavaScript will be very familiar to you. On the other hand, if you are an array noob, you are certainly not alone. Arrays are a sticking point for many new programmers, but alas, salvation is neigh! Allow me to walk you through the creation of a simple JavaScript array, that, for the most part, can also be used in ActionScript.

What is an Array?
An array, at its simplest, is really nothing more than a collection of items that is assigned as a variable. When an item is added to the array, it is given a number called an index. The item can then be referenced later by calling the array variable along with the index number of the item you want to access. Clear as mud? Great! Let’s see an example.

How do I Create an Array?
My wife is making tacos tonight, so I will use my hunger as inspiration.

Awesome, we just created a delicious array!

  1. The first step in creating an array is to declare a variable for it. In this case the variable I want to use is ingredients.
  2. The second step is to cast the variable as an Array object. Some people would argue that this step isn’t necessary, and they’re correct, but it is a best practice to type cast your variables as often as possible.
  3. The third step is to add items to your array. The easiest way to do that is to set your array variable (in this case ingredients) equal to a bracket enclosed, comma delineated list of items. In my case I added three strings to the ingredients array.
  4. The final step isn’t really needed, but is allows you to see what your array looks like at this point. You will see all three comma delineated strings, Beans, Meat, and Cheese in the alert box. This is normal and just means that the array contains all three of those items.

Now, say you’re a meatetarian… How do you only select the one item of the array that you want? It’s actually as easy as grabbing the meat spoon!… so to speak. You just need to call the name of the array variable with the index of the item you want added in brackets (E.g: ingredients[1]).

There is one important thing you should know about indexes in ECMAScript based languages: counting always starts at 0… I don’t know why the rule exists, I just follow it. The first item in your array will always be index 0 (ingredients[0] = Beans in this case), followed by 1, 2, 3 and so on.

This should be enough to help you get started working with Arrays. Check back soon for more on Arrays including some Intermediate and Advanced Array techniques.

2 Comments |  Subscribe to NoobFlash

JavaScript Find and Replace

March 3rd, 2009 by Matthew Hancock, Filed under - JavaScript
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Follow the example below to perform a find and replace in JavaScript.

<script type="text/javascript">
var myString = "I like coding";
myString = myString.replace('coding','sleeping');
document.write(myString);
</script>

Add Comments |  Subscribe to NoobFlash

Flash Player Version Penetration Update

March 3rd, 2009 by Matthew Hancock, Filed under - Flash ~ Flex ~ News ~ Reviews
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Adobe Flash Player Penetration by Version as of December 2008
  v7 v8 v9 v10
Mature Markets 99.1% 99.0% 98.6% 55.9%
US/Canada 99.1% 99.1% 98.9% 54.5%
Europe 99.1% 98.9% 98.2% 56.5%
Japan 99.0% 98.8% 98.3% 59.3%
Emerging Markets 98.7% 98.6% 98.1% 55.9%

Source: Adobe.com

Add Comments |  Subscribe to NoobFlash

Get QueryString Values in JavaScript

February 26th, 2009 by Matthew Hancock, Filed under - Flex ~ HTML ~ JavaScript ~ Opinion
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

I have had several people ask me how to get URL QueryString values in JavaScript, so I created a function that will take a string, find the matching QueryString key, and return the value associated with that key. Enjoy!

NOTE: You may have to remove and re-type the “s from the code below if you copy it from this page. Some of them don’t come through correctly when you paste into your dev application.

Let’s pretend the URL of this page is http://www.noobflash.com/foo/index.html?noob=someValue. The code above will find the first QueryString instance of “noob” in the URL and return the “someValue” portion to be used in your code. You would simply type queryStringValue(”stringToFind”) whenever you would like to get new QueryString data.

Add Comments |  Subscribe to NoobFlash

Send Request

Recent Entries

Archives

Blogroll