Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Dreamweaver Developer Center /

Creating a scoreboard in Spry in five easy steps

by Addam Driver

Addam Driver
  • www.reignwaterdesigns.com

Created

18 May 2008

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
data set Dreamweaver dynamic website notification Spry Spry XML

Requirements

Prerequisite knowledge

Familiarity with building web pages, CSS, JavaScript, and the Spry framework for Ajax.

User level

Intermediate

Required products

  • Dreamweaver (Download trial)

Sample files

  • scoreboard.zip (48 KB)

In this article, I will step you through the process of building a nifty, real-time scoreboard for your sports-viewing pleasures on your personal website. Using the Adobe Spry Data and Effects libraries, you are able not only to get scores and display them; you also have the ability to do exciting things by including notifications and other WOW factors.

Also, check out the following video to learn more about how I discovered and use Spry on the job.

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Step 1: Prepare the data

The first step is to decide on the data you want to include on your scoreboard. For example, a typical scoreboard may contain the following details:

  • Location
  • Team names / Cities
  • Timeouts
  • Foul trouble
  • Scores

Then put the data into an XML file; for example:

<games> <game id="1"> <location>Staples Center, Los Angeles</location> <home> <teamName>Lakers</teamName> <teamCity>Los Angeles</teamCity> <teamStats timeOuts="2" foulTrouble="Kobie Bryant"> <score quarter="1">49</score> <score quarter="2">23</score> <score quarter="3">55</score> </teamStats> </home> <away> <teamName>Heat</teamName> <teamCity>Miami</teamCity> <teamStats timeOuts="5" foulTrouble="Shaq"> <score quarter="1">35</score> <score quarter="2">65</score> <score quarter="3">22</score> </teamStats> </away> </game> </games>

Next, you have to prepare the datasets.

Step 2: Prepare the datasets

When your XML data is ready, you need to prepare the datasets you are going to be working with. Follow these steps:

  1. In Dreamweaver, choose File > New > Basic page > JavaScript to create a new (external) JavaScript file and save it as games.js. This file will contain all of the necessary functions to make things work.
  2. Create the datasets to capture all the information you need. Start with the game information. To your JavaScript file, add:
var dsGames = new Spry.Data.XMLDataSet("games.xml", "games/game");

This is a dataset declaration. It will fetch the XML file andconvert it into a Spry dataset.

  1. Next, capture the home team information. Typically, this informationcontains a lot more data, so you can use the Spry subPaths function tocapture it. I also recommend you use the loadInterval feature toensure the scoreboard can update itself, in this case, every 3 seconds. The useCache option ensures that the new data is fetched from the server:
var dsHome = new Spry.Data.XMLDataSet("games.xml", "/games/game/home", { subPaths: ["teamStats", "teamStats/score" ], loadInterval:3000, useCache:false});
  1. Finally, get the away team information, which follows the same format you used in Step 3:
var dsAway = new Spry.Data.XMLDataSet("games.xml", "/games/game/away", { subPaths: ["teamStats", "teamStats/score" ], loadInterval:3000, useCache:false});

At this point, you're ready to build the HTML page that contains your data.

Step 3: Prepare the HTML page

To prepare the HTML page follow these steps:

  1. In Dreamweaver, choose File > New > Basic page > HTML to create a blank HTML page.
  2. Inside of the <head> section of the document, include the following Spry files. Ensure that the src paths match your file setup. Also, include them in the same order as shown here:
<script language="JavaScript" type="text/javascript" src="/spry/xpath.js"></script> <script language="JavaScript" type="text/javascript" src="/spry/SpryData.js"></script> <script language="JavaScript" type="text/javascript" src="/spry/SpryEffects.js"></script>
  1. Between the <body> tags of the document, add a <div> that will contain all the game information. This helps you keep everythingclean and in order. Now, add the attributes as show below. The spry:detailregion attribute tells Spry that it will be processing data within this tag. Thevalues are the three datasets that you defined above. The names should beseparated by a space:
<div spry:detailregion="dsGames dsHome dsAway"></div>
  1. Next, add some general game information. You want to use data references from the data sets to display the data from the data sets. For this demo, the only global variable is the location of the game. (You can add more as you see fit.) Place it inside of <h1> tags inside the games <div>. It should look something like this:
<div spry:detailregion="dsGames dsHome dsAway" > <h1>{dsGames::location}</h1> </div>

This displays the location data from the dsGames data set. Press F12 to preview the working page in the default browser. You should see "Staples Center, Los Angeles" in large text. If so, your Spry page is working properly. If not, check the code in the sample file and see what differs on your page.

  1. Create the scoreboard table. Inside of the <div>, insert a table (<table>) that will contain the information of each individual game as shown in this snippet:
<div spry:detailregion="dsGames dsHome dsAway" spry:repeat="dsGames"> <h1>{dsGames::location}</h1> <table cellpadding="0" cellspacing="0" border="1"> <tr> <th>&nbsp;</th> <th spry:repeat="dsHome">{dsHome::ds_RowNumberPlus1}</th> <th>Time Outs Used</th> <th>Foul Trouble</th> </tr> <tr> <td>{dsHome::teamName}</td> <td spry:repeat="dsHome" id="hq_{dsHome::teamStats/score/@quarter}">{dsHome::teamStats/score}</td> <td>{dsHome::teamStats/@timeOuts}</td> <td>{dsHome::teamStats/@foulTrouble}</td> </tr> <tr> <td>{dsAway::teamName}</td> <td spry:repeat="dsAway" id="aq_{dsAway::teamStats/score/@quarter}">{dsAway::teamStats/score}</td> <td>{dsAway::teamStats/@timeOuts}</td> <td>{dsAway::teamStats/@foulTrouble}</td> </tr> </table> </div>

This is the main part of the scorecard. Preview in browser to ensure it is working properly.

Step 4: Prepare score capturing for the WOW factor

Now that your scoreboard is up and running, you can add a notification feature that alerts users when a team has scored. There are obviously many different ways you can notify the viewer that something has changed. For this tutorial, you are going to highlight the box that contains the updated score.

The filter you create will capture the current scores, get the new set of scores and check to see if anything has changed. If they have changed, then find the location of the score and highlight the box.

Follow these steps:

  1. Create the filter function and score holder dataset. Inside of your JavaScript file, create the following variables and function:
var HScoreHolder = new Array(); // Home Score Holder var AScoreHolder = new Array(); // Away Score Holder var scoreHolder = new Array(); // Template Score Holder function GetScoreUpdateFunc(scoreHolder, prefixStr){ // Get score function }

This particular function is a wrapper for the real function. This enables you to use the filter as a template, so you can use it for more than one dataset (I'll explain that shortly). Here is the actual filter function:

var scoreHolder = new Array(); // Generic Score Holder function GetScoreUpdateFunc(scoreHolder, prefixStr){ // Get score function return function (ds, row, rowIndex){ // return the actual filter function return row; }; }
  1. Add a key:
var scoreHolder = new Array(); // Generic Score Holder function GetScoreUpdateFunc(scoreHolder, prefixStr){ // Get score function return function (ds, row, rowIndex){ // return the actual filter function var key = prefixStr+row['teamStats/score/@quarter']; // create a key for the games return row; }; }

Note that this key is basically the same value as the generated id for the score boxes in the markup. The key represents the location of the score. If you look in the mark-up above, you'll notice the following ID: id="aq_{dsAway::teamStats/score/@quarter}". This is a unique ID for each quarter. This way you can keep track of where each score is located. The var key = indicates the location of the score in its respective box.

  1. Capture and store the score information and return the regular data to the dataset:
var scoreHolder = new Array(); // Generic Score Holder function GetScoreUpdateFunc(scoreHolder, prefixStr){ // Get score function return function (ds, row, rowIndex){ // return the actual filter function var key = prefixStr+row['teamStats/score/@quarter']; // create a key for the games scoreHolder[key]= new Array(); // make each key an array scoreHolder[key]= row['teamStats/score']; // get the current scores return row; }; }
  1. Now you need a way to check the scores. Fortunately, JavaScript reads from the top down and left to right. So in between the key and the score holder array, you will insert a simple if statement that will call a function that then verifies whether the score holder array has been set. If so, it will then verify whether its value differs from the new scores. If it does, you will tell it to highlight the box from an orange color to white in 3 seconds. Here's the code:
var scoreHolder = new Array(); // Generic Score Holder function GetScoreUpdateFunc(scoreHolder, prefixStr){ // Get score function return function (ds, row, rowIndex){ // return the actual filter function var key = prefixStr+row['teamStats/score/@quarter']; // create a key for the games if(scoreHolder[key]){ // check for keys already set if(row['teamStats/score'] != scoreHolder[key]){ Spry.Effect.DoHighlight(key,{duration:3000,from:'#FB9A00', to:'#fff', restoreColor:'#fff'});// highlight the updated score box } } scoreHolder[key]= new Array(); // make each key an array scoreHolder[key]= row['teamStats/score']; // get the current scores return row; }; }

Step 5: Kick off the filter

Now that you've got it all set up, you can start on the filter. After GetScoreUpdateFunc, add two filter calls to the datasets (Home and Away) that will capture and check the data:

dsHome.filter(GetScoreUpdateFunc(HScoreHolder, "hq_")); // Filter for home scores... Check for updates dsAway.filter(GetScoreUpdateFunc(AScoreHolder, "aq_")); // Filter for away scores... Check for updates

Your scoreboard is now complete. If you update any of the scores inside of the XML, you will see it update on the page; you will also see the nifty little background orange color. For your reference, refer to the simple sample scoreboard I've included with this article.

You have various options to update your information. You can do it manually to see your new scoreboard application in action. Other methods include, using a back-end database to keep track of your scores and making a Spry-Ajax call to a PHP, JSP, ASP or other server-side application that will just fetch the new data for you in an XML format.

Where to go from here

Not bad what you can do with Spry, isn't it? If you want to take this even further, you could add a total score or other information like fouls, time-outs, and so on. Get creative and add multiple scoreboards or add more games to your XML.

More Like This

  • Creating a multiscreen theme for WordPress using Dreamweaver CS5.5
  • Building Drupal Zen subthemes with Dreamweaver CS4
  • Creating master and detail ColdFusion pages
  • Creating user-defined functions for ColdFusion 8 in Dreamweaver CS4
  • Creating a ColdFusion upload page in Dreamweaver CS4
  • Creating custom server behaviors and Dreamweaver extensions
  • Managing multiple subscriptions in PHP
  • Building a subscribe/unsubscribe app in PHP with Dreamweaver CS3
  • Designing for web publishing
  • XML in the real world

Tutorials and samples

Tutorials

  • Understanding HTML5 semantics: Changed and absent elements
  • Mobile app with PhoneGap: Submitting to the Apple App Store
  • PhoneGap and Dreamweaver: Releasing on iOS
  • Mobile app with PhoneGap: Submitting to Android Market

Samples

  • Responsive design with jQuery marquee
  • Customizable starter design for jQuery Mobile
  • Customizable starter design for HTML5 video
  • Customizable starter design for multiscreen development

Dreamweaver user forum

More
04/23/2012 Resolution/Compatibility/liquid layout
04/20/2012 using local/testing server with cs5 inserting images look fine in the split screen but do not show
04/18/2012 Ap Div help
04/23/2012 Updating

Dreamweaver Cookbook

More
11/07/2011 Simple social networking share buttons
09/20/2011 Registration form that will generate email for registrant to validate
08/21/2011 Spry Accordion - Vertical Text - Auto Start on Page Load - Mouse Over Pause
08/17/2011 Using cfdump anywhere you like

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement