XML

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentXML

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old April 6th, 2007, 06:27 AM
James croft James croft is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 7 James croft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 4 sec
Reputation Power: 0
Angry load and unload XML files

Hi all. I am making a picture gallery using Macromedia flash 8. In my gallery, most of the objects are drawn by using action script. I copied the action script of Macromedia/Flash8/Samples and tutorials/Action Script/Gallereis/Gallery_tween.fla and modified it a little. In this gallery_tween.fla, it loads XML file and display the nodes (pictures) in different movieClips.

The result I need
I need to load two XML files. There are two buttons in my gallery. One is gallery1_btn and the other is gallery2_btn. I also have gallery1_tween.xml and gallery2_tween.xml in the same directory where my flash file(.fla file) is saved.
I want my flash file to load gallery1_tween.xml when I press gallery1_btn and when I press gallery2_btn, I want my falsh file to unload gallery1_tween.xml and load gallery2_tween.xml.

The current result
By using the action script below, I were able to load gallery1_tween.xml when I press gallery1_btn and load gallery2_tween.xml when I press gallery2_btn. But I were unable to unload gallery2_tween.xml when I press gallery1_btn and unload gallery1_tween.xml when I press gallery2_btn.

Below is the action script. You many copy the code and paste it in actions panel. It will work if you make XML file and save in the same directory where your save your work. You can find sample XML file in Macromedia/flash 8/ samples and tutorials/action script/galleries/gallery_tween.xml.

import mx.transitions.*;
import flash.geom.*;
_global.thisX = 30;
_global.thisY = 70;
_global.stageWidth = 600;
_global.stageHeight = 400;
var gallery_xml:XML = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success:Boolean) {
try {
if (success) {
var images:Array = this.firstChild.childNodes;
var gallery_array:Array = new Array();
for (var i = 0; i<images.length; i++) {
gallery_array.push({src:images[i].firstChild.nodeValue});
}
displayGallery(gallery_array);
} else {
throw new Error("Unable to parse XML");
}
} catch (e_err:Error) {
trace(e_err.message);
} finally {
delete this;
}
};
function displayGallery(gallery_array:Array) {
var galleryLength:Number = gallery_array.length;
for (var i = 0; i<galleryLength; i++) {
var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
mcLoader_mcl.loadClip(gallery_array[i].src, thisMC);
preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
preloaderMC.bar_mc._xscale = 0;
preloaderMC.progress_txt.text = "0%";
thisMC._x = _global.thisX;
thisMC._y = _global.thisY;
preloaderMC._x = _global.thisX;
preloaderMC._y = _global.thisY+20;
if ((i+1)%5 == 0) {
_global.thisX = 20;
_global.thisY += 80;
} else {
_global.thisX += 80+20;
}
}
}
var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function() {
};
mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
preloaderMC.bar_mc._xscale = pctLoaded;
preloaderMC.progress_txt.text = pctLoaded+"%";
};
mclListener.onLoadInit = function(evt:MovieClip) {
evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
var thisWidth:Number = evt._width;
var thisHeight:Number = evt._height;
var borderWidth:Number = 2;
var marginWidth:Number = 8;
evt.scale = 20;
evt.lineStyle(borderWidth, 0x000000, 100);
evt.beginFill(0xFFFFFF, 100);
evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.endFill();
evt._xscale = evt.scale;
evt._yscale = evt.scale;
evt._rotation = Math.round(Math.random()*-10)+5;
evt.onPress = function() {
this.startDrag();
this._xscale = 100;
this._yscale = 100;
this.origX = this._x;
this.origY = this._y;
this.origDepth = this.getDepth();
this.swapDepths(this._parent.getNextHighestDepth() );
this._x = (_global.stageWidth-evt._width+30)/2;
this._y = (_global.stageHeight-evt._height+30)/2;
mx.transitions.TransitionManager.start(this, {type:mx.transitions.Photo, direction:0, duration:1, easing:mx.transitions.easing.Strong.easeOut, param1:empty, param2:empty});
};
evt.onRelease = function() {
this.stopDrag();
this._xscale = this.scale;
this._yscale = this.scale;
this._x = this.origX;
this._y = this.origY;
};
evt.onReleaseOutside = evt.onRelease;
};
mcLoader_mcl.addListener(mclListener);
//galley1 button
_root.createEmptyMovieClip("gallery1_btn",_root.getNextHighestDepth());
with(gallery1_btn){
colors = [0x9C94E7, 0x4D44D5, 0x7473DE];
fillType = "linear"
alphas = [100, 100, 100];
ratios = [0, 0xFF,0xFF];
spreadMethod = "reflect";
interpolationMethod = "linearRGB";
focalPointRatio = 0.9;
matrix = new Matrix();
matrix.createGradientBox(100, 100, Math.PI, 0, 0);
beginGradientFill(fillType, colors, alphas, ratios, matrix,
spreadMethod, interpolationMethod, focalPointRatio);
lineStyle(2,0x000000,100);
moveTo(100,100);
lineTo(100,125);
lineTo(200,125);
lineTo(200,100);
lineTo(100,100);
_x=300;
_y=260;
}
//
//gallery2 button
_root.createEmptyMovieClip("gallery2_btn",_root.getNextHighestDepth());
with(General){
colors=[0xffcc99, 0xddbbb33,0xfacb32];
fillType="linear";
alphas=[100,100,100];
spreadMethod="reflect";
interpolationMethod="linearRGB";
focalPointRatio=0.9;
matrix= new Matrix();
matrix.createGradientBox(100,100,Math.PI,0,0);
beginGradientFill(fillType,colors,alphas,ratios,ma trix,spreadMethod,interpolationMethod,focalPointRa tio);
lineStyle(2,0x000000,100);
moveTo(100,100);
lineTo(100,125);
lineTo(200,125);
lineTo(200,100);
lineTo(100,100);
_x=(_root.Saalhanga._x)-100;
_y=260;
}
//
_root.gallery1_btn.onRelease=function(){
unload (gallery_xml.load("gallery2_tween.xml"));
gallery_xml.load("gallery1_tween.xml");
resetCordinates();
}
_root.gallery2_btn.onRelease=function(){
unload (gallery_xml.load("gallery1_tween.xml"));
gallery_xml.load("gallery_tween2.xml");
resetCordinates();
}
function resetCordinates(){
_global.thisX=20;
_global.thisY=80;
}



Please help me fixing this problem. Any suggestions or questions are all welcomed.

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentXML > load and unload XML files


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap