ActionScript 3 Extensible Markup Language (XML) by Martin Stanhope The University of Bolton.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1.
Java Script Session1 INTRODUCTION.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
The Web Warrior Guide to Web Design Technologies
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
Introduction to XML This material is based heavily on the tutorial by the same name at
Introduction to scripting
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
4.1 JavaScript Introduction
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
Languages in WEB Presented by: Jenisha Kshatriya BCM SS09.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
HTML Structure & syntax
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
Agenda Links External and Internet Links Anchor Tag Text Hyperlinks Image Hyperlinks Images Image Attributes: src, alt, width, height, align, border.
Lecture 13 – XML and JSON SFDV3011 – Advanced Web Development Reference: 1.
F-1 Management Information Systems for the Information Age Copyright 2004 The McGraw-Hill Companies, Inc. All rights reserved Extended Learning Module.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Tutorial 1: XML Creating an XML Document. 2 Introducing XML XML stands for Extensible Markup Language. A markup language specifies the structure and content.
Computer Information Technology – Section 3-4. HTML – The Language of the Internet Objectives: The Student will: 1. Look at HTML 2. Understand the basic.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 8 Programming with ActionScript 3.0. XP Objectives Review the basics of ActionScript programming Compare ActionScript 2.0 and ActionScript 3.0.
Using Client-Side Scripts to Enhance Web Applications 1.
Copyright 2007, Information Builders. Slide 1 Understanding Basic HTML Amanda Regan Technical Director June, 2008.
CIS 451: USING ASP.NET TO CREATE XML Dr. Ralph D. Westfall February, 2009.
XHTML1 Images N100 Building a Simple Web Page. XHTML2 The Element The src attribute specifies the filename of an image file To include the src attribute.
HTML Structure & syntax. Introduction This presentation introduces the following: Doctype declaration HTML Tags, Elements and Attributes Sections of a.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
XP 1 Creating an XML Document Developing an XML Document for the Jazz Warehouse XML Tutorial.
Database Handling, Sessions, and AJAX. Post Back ASP.NET Functionality The IsPostBack method in ASP.NET is similar to the BlackBerry.refresh method –IsPostBack.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
Introducing the World Wide Web Internet- a structure made up of millions of interconnected computers whose users communicate with each other and share.
1 JavaScript
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
ActionScript 3 Using Sound Related Classes by Martin Stanhope The University of Bolton.
The Web Wizard’s Guide to HTML Chapter One World Wide Web Basics.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
Exceptions, handling exceptions & message boxes Year 11 Information Technology.
Unit 3 — Advanced Internet Technologies Lesson 11 — Introduction to XSL.
Representing data with XML SE-2030 Dr. Mark L. Hornick 1.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Understanding JavaScript and Coding Essentials Lesson 8.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
JQUERY AND AJAX
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
Section 10.1 Define scripting
Project 1 Introduction to HTML.
XML and Flash © University of South Wales.
Web DB Programming: PHP
Tutorial 10: Programming with javascript
Introduction to Programming and JavaScript
Presentation transcript:

ActionScript 3 Extensible Markup Language (XML) by Martin Stanhope The University of Bolton

What is XML? HTML (HyperText Markup Language) uses predefined tags such as,,, to format information for displaying in web pages. XML (Extensible Markup Language) uses user- defined tags for the purpose of structuring data not for the purpose of displaying it. XML is a markup language used to structure, format and describe data. XML documents are simple text files that are used for exchanging data across the Internet or dissimilar applications.

What is an XML document? "The Stranglers" "Golden Brown" "GoldenBrown.mp3" "The Stranglers" "Something Better Change" "SomethingBetterChange.mp3" "The Stranglers" "Tank" "Tank.mp3" playlist.xml

XML terminology XML tag - These are user defined and are used to mark the beginning and end of a piece of information. Eg.. XML element - An XML element is a collection of an opening tag, the corresponding closing tag and the information between them, for example, an example of a track element is: "Stranglers" "Something Better Change" "SomethingBetterChange.mp3" Note how this track element contains 3 other elements. XML tree. The top-down listing of elements playlist track artist trackname filename

XML objects Qu. How is XML dealt with in ActionScript 3? Ans. By the use of XML objects created from the class named XML. XML objects can be created and dealt with in the following ways: Method 1 Create an XML object and insert the information into it (i.e. 'populate' it) by assigning an 'XML literal' to it. Method 2 Create an XML object by passing an XML string to the XML class constructor. Method 3 Create an XML object (an unpopulated one), and populate it by inserting one element at a time using AS3 statements. Method 4 Create an XML object (an unpopulated one), and fill it with data from an external XML file.

XML objects – Using method 1 Method 1- Create an XML object and insert the information into it (i.e. 'populate' it) by assigning an 'XML literal' to it. var student:XML = Joe Bloggs ; // Display the XML object including tags and data trace(student);

XML objects – Method 1 expanded var students:XML = Joe Bloggs Sue Jones ; trace(students);

XML objects – Method 2 Method 2 - Create an XML object by passing an XML string to the XML class constructor. var firstname = "Joe"; var lastname = "Bloggs"; var idnumber = " "; var str:String = " " + " " + firstname + " " + " " + lastname + " " + " " + idnumber + " " + " "; var student:XML = new XML(str); trace(student);

XML objects – Method 3 Method 3 - Create an XML object (an unpopulated one), and populate it by inserting one element at a time using AS3 statements. var student:XML = ; // Create an XML object with a root element student.firstname = ; // Create subelement student.lastname = ; // Create subelement student.idnumber = “ “; // Create subelement trace(student); // Now put some information into the XML object student.firstname = "Joe"; student.lastname = "Bloggs"; student.idnumber = " "; trace(student);

XML objects – Method 4 Method 4 - Create an XML object (an unpopulated one), and fill it with data from an external XML file. // Put file name into a string variable var mySampleFile:String = "playlist.xml"; // Create a new URLRequest object to specify the filename (and location) var myRequest:URLRequest = new URLRequest(mySampleFile); // Create a new loader object var myLoader:URLLoader = new URLLoader(); // Tell the loader to load the file as plain text. myLoader.dataFormat = URLLoaderDataFormat.TEXT; // Register the event handler to invoke a COMPLETE event when XML file loaded myLoader.addEventListener( Event.COMPLETE, onComplete ); // Load the XML file myLoader.load(myRequest);

XML objects – Method 4 short version The following is the same as the previous slide but in a short version… var myLoader:URLLoader = new URLLoader(); myLoader.dataFormat = URLLoaderDataFormat.TEXT; myLoader.addEventListener( Event.COMPLETE, onComplete ); myLoader.load( new URLRequest("playlist.xml") );

XML objects – Method 4 – The event handler The statement to register the event that triggers when the XML file has completely loaded is: myLoader.addEventListener( Event.COMPLETE, onComplete ); An event handler function named onComplete is required to… 1.‘Receive’ the event and assign it to a local variable (named e in this example). 2.Assign the event target data (i.e. the XML text that has been fully downloaded) to an XML object 3.Do something with the data. private function onComplete( e:Event ):void { var myXML:XML = new XML( e.target.data ); trace( myXML ); }

XML objects – Method 4 – More useful event handler code var counter:uint = 1; // a counter // Display a list of track names for each ( var myElement:XML in myXML.elements() ) { _displayTXT.appendText(counter + " " + myElement.trackname + "\n"); counter++; // increment the counter by 1 } // Demo of selecting a particular track filename, e.g. the first track is indexed // using the index number zero (as in arrays). _displayTXT.appendText("\n\n" + myXML.track[0].filename + "\n");

XML objects – Method 4 – More useful event handler code The above code causes the following to be displayed in the dynamic text field... 1 Golden Brown 2 Something Better Change 3 Tank GoldenBrown.mp3 The code demonstrates the two features you will need for the assignment: The means of displaying a list of available track titles. The means of selecting a track file name from all the track filenames held in the XML object.

XML objects – Method 4 – Problems with XML text files What happens if the external XML file doesn't load (perhaps because its content is not a valid XML structure)? To deal with such a situation the event handler has to… try to deal with the event If there is a problem it will generate an error condition which can be caught and dealt with by issuing an error message to the user.

XML objects – Method 4 – The try…catch block private function onComplete( e:Event ):void { try { var myXML:XML = new XML( e.target.data ); trace( myXML ); } catch ( e:TypeError ) { //If this section is executed then the downloaded file //could not be converted into an XML object, //possibly due to incorrect formating of the XML //code in the text file trace( "CATCH: Error. Could not parse text into XML"); trace( "CATCH: Error. " + e.message ); } }//End of event handler onComplete

Workshop Exercises Exercise 1 – Trials with the first 3 methods of creating XML objects Method1.as / Method1.fla Method1b.as / Method1b.fla Method2.as / Method2.fla Method3.as / Method3.fla Exercise 2 – Trials with method 4, creating an XML object using external XML data files (e.g. student-data.xml and playlist.xml) XMLloader1.as / XMLloader1.fla XMLloader2.as / XMLloader2.fla XMLloader3.as / XMLloader3.fla XMLloader4.as / XMLloader4.fla XMLloader5.as / XMLloader5.fla Exercise 3 – Creating an XML data file of your own then writing an AS3 application to load in the file and to display its data in a dynamic text field.