Topic: Changing xml source without "rebuilding" html object with javascript

Hi,

is it possible to change xml src for gallery through API without need to rebuild whole emmbed object with javascript?

Something like showImage(index) for switching between images in xml, but "loadXmlSrc(path)"?

For now to switch galleries I have to clear previous object, create new and place it in html. It eats some browser memory to do using SWFObject. (+Opera is a bit tricky with displaying refreshed SWFObject. So far no idea why.)

Namely, my script does:

swfobject.removeSWF('flashContent');
// declaring new SV gallery vars
swfobject.embedSWF('flashContent',...);

I'm looking for:

svAPI.changeXmlSrc(path_to_new_xml);

Re: Changing xml source without "rebuilding" html object with javascript

There is no change XML option in the API, available API options can be found here, you can however use galleryURL to set the XML.

flashvars.galleryURL = "gallery.xml";

Mike Richards
SimpleViewer Support Team.

Re: Changing xml source without "rebuilding" html object with javascript

So,

did you get this sorted?
I'd like to use something like this too.
I'm developing a page for a wedding-photographer and would like the people to select their own gallery through a dropdown box wich should select the right xml and thus show the right gallery...
I've been searching this forum and google, yet I can't find a solution and I'm just a self-made man that uses the power of google and trial-and-error...   roll

Thanks!

Re: Changing xml source without "rebuilding" html object with javascript

The easiest way to change the gallery without the page refreshing is to use multiple galleries within flash. There is an example included with the pro download.

Mike Richards
SimpleViewer Support Team.

Re: Changing xml source without "rebuilding" html object with javascript

Thanks for the reply Miker,

and yes, I have seen the example,
however, it stil needs a button per gallery.
When there are 20+ galleries there need to be 20+ buttons, correct me if I'm wrong.
Thats why I was thinking about dropdown boxes...
I haven't got a problem with figuring things out, I just need to be sure it's do-able  smile

Thanks again!

Re: Changing xml source without "rebuilding" html object with javascript

You can do drop downs in flash or in HTML and pass the data to the flash.

Mike Richards
SimpleViewer Support Team.

Re: Changing xml source without "rebuilding" html object with javascript

Hi miker,

what do you mean by "multiple galleries within flash"?

This example switches directories thus reloading page:
http://www.simpleviewer.net/simpleviewe … index.html

Re: Changing xml source without "rebuilding" html object with javascript

Instead of embedding SimpleViewer into the HTML you embed it into a swf. You can see the example included with the Pro download here selecting gallery 1 or gallery 2 will load a new gallery but not refresh the page.

Mike Richards
SimpleViewer Support Team.

Re: Changing xml source without "rebuilding" html object with javascript

I'm looking for:
svAPI.changeXmlSrc(path_to_new_xml);

Currently SimpleViewer does not support this functionality. The problem is that the SimpleViewer SWF needs to be reloaded when the XML is switched. You can use SWFObject to reload the SWF. Check 'Replacing a loaded SWF with another SWF' here for more details: http://learnswfobject.com/advanced-topi … ick-event/

The easiest way to switch the gallery XML is by navigating to a new URL which contains a new gallery. Since the SWF is cached it will not take long to reload. Also this method handles the browser back button automatically. For an example of this approach, check the 'Multiple Galleries on Separate HTML Pages' instructions here: http://www.simpleviewer.net/simpleviewe … l#multiple

Felix Turner
SimpleViewer Support Team.

Re: Changing xml source without "rebuilding" html object with javascript

Thanks guys!

All sorted out now.

I had a feeling that gallery SWF is kind of 'initialized' with given XML file and needs to be 'reinitialized' for the new XML, it turned out to be true.
Second point here - it won't  take long time to reload SWF through replacing SWFObject - it's true too. It's just, you know, since developer's goal to optimize - can't get enough of it. Doing replacement now, it works good.
And third - don't want to mess with FLA( http://www.simpleviewer.net/simpleviewe … ash_embed/ ), yet. But thanks to miker for posting this example.

Thanks for answers.

To give some info for future reference maybe, posting current code(or quite close to it):

<html>
  <head>
  <script src="prototype.js"></script>
  <script src="swfobject.js"></script>

  <script>
  var defaultGallery = 1;
  var firstRun = true;

  function showGallery(galleryNumber) {
    if(!galleryNumber)
      galleryNumber = defaultGallery;
      
    if(firstRun) {
      firstRun = false;
    } else {
      // remove existing embed object
      swfobject.removeSWF('flashContent');
      
      // some extra code to create new <div id="flashContent"></div>
      // because swfobject.removeSWF() does remove complete <div>(which is later <object>)
    }
    

    // setting vars, params, ...
    var flashvars = {
      galleryURL : "/xml/gallery_"+galleryNumber+".xml"
    };
    
    var flashparams = {};
    
    swfobject.embedSWF("/swf/viewer.swf", "flashContent", "100%", "100%", "9.0.124", false, flashvars, params);
  }

  Event.observe(window, 'load', showGallery);
  </script>

  </head>
  <body>

  <a href="javascript:showGallery(1)">Gallery 1</a>
  <br />
  <a href="javascript:showGallery(2)">Gallery 2</a>

  
  <div id="flashContent"></div>

  </body>
</html>

Thanks again!

Anton.

Re: Changing xml source without "rebuilding" html object with javascript

So,
I kind of got it working.
I have my dropdown-menu in flash, based on xml which refreshes the galleries dynamically.
However, I can't get the first gallery to load by default. I have to manually select one to view something.
In the standard code the first gallery is loaded using the function: Loadgallery(1)
Because I had to change the code a bit, the Loadgallery function had to be replaced.
Could someone point me out how I can make it load my gallery1.xml by standard?
It would be grately appreciated!

//Example of loading multiple SimpleViewer swfs into another flash movie.

//init stage
Stage.align = "TL"; 
Stage.scaleMode = "noScale";

//set width and height of SimpleViewer swf
_global.SVStageWidth = 640;
_global.SVStageHeight = 420;

var galleryId:Number;
var mLoader_mcl = new MovieClipLoader();
mLoader_mcl.addListener(this);


// generates a list of menu items (effectively one menu)
// given the inputted parameters.  This makes the main menu
// as well as any of the submenus
GenerateMenu = function(container, name, x, y, depth, node_xml) {
    // variable declarations
    var curr_node;
    var curr_item;
    var curr_menu = container.createEmptyMovieClip(name, depth);
    
    // for all items or XML nodes (items and menus)
    // within this node_xml passed for this menu
    for (var i=0; i<node_xml.childNodes.length; i++) {
        // movieclip for each menu item
        curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
        curr_item._x = x;
        curr_item._y = y + i*curr_item._height;
        curr_item.trackAsMenu = true;
        
        // item properties assigned from XML
        curr_node = node_xml.childNodes[i];
        curr_item.action = curr_node.attributes.action;
        curr_item.variables = curr_node.attributes.variables;
        curr_item.name.text = curr_node.attributes.name;
        
        // item submenu behavior for rollover event
        if (node_xml.childNodes[i].nodeName == "menu"){
            // open a submenu
            curr_item.node_xml = curr_node;
            curr_item.onRollOver = curr_item.onDragOver = function(){
                var x = this._x + this._width - 5;
                var y = this._y + 5;
                GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml);
                // show a hover color
                var col = new Color(this.background);
                col.setRGB(0xf4faff);
            };
        }else{ // nodeName == "item"
            curr_item.arrow._visible = false;
            // close existing submenu
            curr_item.onRollOver = curr_item.onDragOver = function(){
                curr_menu.submenu_mc.removeMovieClip();
                // show a hover color
                var col = new Color(this.background);
                col.setRGB(0xf4faff);
            };
        }
        
        curr_item.onRollOut = curr_item.onDragOut = function(){
            // restore color
            var col = new Color(this.background);
            col.setTransform({ra:100,rb:0,ga:100,gb:0,ba:100,bb:0});
        };
        
        // any item, menu opening or not can have actions
        curr_item.onRelease = function(){
            Actions[this.action](this.variables);
            CloseSubmenus();
        };
    } // end for loop
};

// create the main menu, this will be constantly visible
CreateMainMenu = function(x, y, depth, menu_xml){
    // generate a menu list
    GenerateMenu(this, "mainmenu_mc", x, y, depth, menu_xml.firstChild);
    // close only submenus if visible durring a mouseup
    // this main menu (mainmenu_mc) will remain
    mainmenu_mc.onMouseUp = function(){
        if (mainmenu_mc.submenu_mc && !mainmenu_mc.hitTest(_root._xmouse, _root._ymouse, true)){
            CloseSubmenus();
        }
    };
};

// closes all submenus by removing the submenu_mc
// in the main menu (if it exists)
CloseSubmenus = function(){
    mainmenu_mc.submenu_mc.removeMovieClip();
};

// This actions object handles methods for actions
// defined by the XML called when a menu item is pressed
Actions = Object();
Actions.gotoURL = function(urlVar){
    getURL(urlVar, "_blank");
};
Actions.message = function(msg){
    message_txt.text = msg;
};
Actions.newMenu = function(menuxml){
    menu_xml.load(menuxml);
};
Actions.gallerij = function(gallery) {
    galleryId = gallery ;
    mLoader_mcl.loadClip("viewer.swf",mcLoader);
};



// load XML, when done, run CreateMainMenu to interpret it
menu_xml = new XML();
menu_xml.ignoreWhite = true;
menu_xml.onLoad = function(ok){
    // create main menu after successful loading of XML
    if (ok){
        CreateMainMenu(-455, -60, 0, this);
        message_txt.text = "message area";
    }else{
        message_txt.text = "error:  XML not successfully loaded";
    }
};
// load first XML menu
menu_xml.load("menu1.xml");



function onLoadInit(){
    
    //set gallery xml name
    _root.xmlDataPath = "gallery"+galleryId + ".xml";
    
}

//load first gallery

loadGallery(1);

Last edited by Quinstar (2010-07-17 09:14:16)

Re: Changing xml source without "rebuilding" html object with javascript

@Quinstar: sorry can't help with FLA files, but if you will have any questions about javascript API, I'll be glad to help you