| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
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. |
![]() |
| Viewing: Tutorialized Forums > Web Design & Development > XML > load and unload XML files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|