Free tools
Tutorial Automated
Tutorial Automated is our free tool for tutorial submission on tutorial indexing sites.
www.omnetwork.net/ta

Color Analyzer
Color Analyzer is free color matching tool for designers, using several algorithms.

www.omnetwork.net

Free&Royalty Free Photos (Random)
Aparmants LCD display with dollar sign Leaves Sky Downtown
Search Photos and Resources
 
Web www.omnetwork.net
Recent News
About Author
Author: hardyvoje
From: Serbia
Interest: omnetwork.net
Article Info
Published: 2006-01-15
Read: 10296 times
Rating: 8.20 (5)

Small dynamic-flash news block feeding with XML

Required software: Macromedia Flash MX

The aim of this tutorial is to teach you how to create dynamicly feeded from XML news block for your site. Described metod is usefull for every XML->Flash integration. After figuring this out you will be able to manipulate with data providen in XML.

1.Content of FLA and ZIP

We will skip things that you should know in order to create object provided in FLA file and just quote what you have in. Download flashnews.zip here



In Layer 2 you have MovieClip instance called Cover. This we gonna use to hide and

unhide news content while text changing after user clicked on Next to switch to earlier

item. Cover has two Stop() commands, and the beginning of animation (cover is totaly

opened) and at the middle of animation (cover is totaly closed), but there is code at last frame

(totaly cosed): _root.LoadNews();
When cover is closed it calls function to load next entry


In Layer 1 you have dynamic text fiels objects with instance names:
news_title -> holding story's title
news_date -> holding story's date
news_text_field -> holding story's text
news_num_display -> showing to user entry number / number of entries

There is also button objects:
Link button that opens realated URL in new browser window
Next button switching to next entry

In this .zip is dog.xml file in which news are stored.

2.Code

// [Action in Frame 1, Layer 1]
function loadXMLNews(loaded) {
	if (loaded) {
		// If XML file is loaded this will open Cover
		_root.cover.gotoAndPlay(2);
		// Geting information from XML object and puting it in text fields
		_global.number = this.firstChild.firstChild.childNodes[0].nodeValue;
		_root.news_title.text = 

this.firstChild.childNodes[_global.sel].childNodes[0].firstChild.nodeValue;
		_root.news_date.text = 

this.firstChild.childNodes[_global.sel].childNodes[1].firstChild.nodeValue;
		_root.news_text_field.text = 

this.firstChild.childNodes[_global.sel].childNodes[2].firstChild.nodeValue;
		_root.news_num_display.text = _global.sel+"/"+_global.number;
		_global.related_link = 

this.firstChild.childNodes[_global.sel].childNodes[2].firstChild.nodeValue;
		if (_global.related_link=="") {_root.linkbutton._visible=false;} else 

{_root.linkbutton._visible=true;}
		// last line hides Link button if there is no link related to entry
		} else {
		trace("file dog.xml not loaded!");
		// shown in output pane if dog.xml from some reason is not readible
	}
}
function LoadNews() {
	xmlNews = new XML();
	// instancing new XML object
	xmlNews.ignoreWhite = true;
	// ignore white spaces in XML file
	xmlNews.onLoad = loadXMLNews;
	// trigger loadXMLNews function when loading is finished.
	xmlNews.load("dog.xml");
	// specify which file to open
}


These functions loading dog.xml file and retrives data.
This code is at first frame, Layer 1

_global.sel = 1;
// sets defauls entry number, the first one.
LoadNews();
stop();


This is the main code that calls LoadNews function and sets _global.set as 1 to point

on first entry. At the end stop() stops movie playback to avoid contant repeating.

_global.sel = 1;
LoadNews();
stop ();


Code shown above will load only first entry, in order to allow visitors to switch entries we gonna

put these code in Next button:

on (release) {
	if (_global.sel<_global.number) {
		_global.sel++;
		// selecting next entry
	} else {
		_global.sel = 1;
		// if Selecter is not less then number of entries that means
		// that we are at last entry so we going back to 1.
	}
		_root.cover.gotoAndPlay(11);
		// triggering Cover to start closing
}


And at the last frame in Cover MC instance:
_root.LoadNews();
// when cover is closed it calls function to load next entry


Now we will put code into Link button to make our script opening provided link:
on (release) {
getURL(_global.related_url, "_blank");
// This will open new browser window (because of _blank flag) with related URL.
}

Note: XML using UTF-8 so it's usable for any language.

see it on-line:
http://www.omnetwork.net/cms/tutimages/news.swf
Printer Friendly PageTell a Friend Export PDF file

1 2 3 4 5 6 7 8 9 10
The comments are owned by the poster. We aren't responsible for their content.

Buy and Sell Links!
Text Link Ads

Text Link Ads
Random photo
Sky
Recent Article
Recent FREE resource
Joomla Square Template by omnetwork.net
Version: 1
Templates
Size: 34 KB
Date: 12/02/2007
Sent by: hardyvoje
Who's Online
9 user(s) are online (2 user(s) are browsing Articles&Tutorials)

Members: 0
Guests: 9

more...
Login
Username:

Password:


Lost Password?

Register now!
2005-2006 | made in Serbia