dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: offline Flash XML Database

  1. #1
    Member
    Join Date
    Jul 2003
    Location
    Brampton, ONT
    Posts
    50

    offline Flash XML Database

    Hi all,

    My task at hand is to build an offline Flash module that is XML database driven.

    Basically I have like 20 chapters that contain different .swf files that I would like to be loaded and displayed on my module.

    Is there a way I can build my database and search it in flash?

    Can any one point me to the right direction or just throw me some pointers?

  2. #2
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    If the size of your XML database isn't too big you can search it easily in Flash, but as the database grows performance will suffer.

    You can visit php.net and get a copy of PHP that runs locally and use that with a copy of MySQL for win32 from mysql.com. You will also need a local (personal) web server as well. So, it will require a bit of installation magic but the advantage is you can use pretty much the same solution as you use from Flash online today.

    The major third party projector tools offer some kind of database connectivity where you can access ODBC or ADO data sources from Flash through extended FSCommands. I know for sure that SWF Studio (my product) and Flash Studio allow this and I believe SWFKit does as well.

    SWF Studio http://www.northcode.com
    Flash Studio http://www.multidmedia.com
    SWFKit http://www.swfkit.com
    SWiSH Studio http://www.swishzone.com
    FlashAnts http://www.flashants.com
    LPFlashEX http://www.logicplus.com.hk
    Flash 'N Pack http://www.flashnpack.com
    Jugglor http://www.***********.com

    If all you need to do is search (not add data) then check out this thread http://www.flashkit.com/board/showth...hreadid=555441 and you'll find a link to an example application created with SWF Studio that allows you to search a 50,000+ entry phone database using tab delimited text files as the data source to search.

  3. #3
    Member
    Join Date
    Jul 2003
    Location
    Brampton, ONT
    Posts
    50

    Follow-up

    Thanks for the reply...

    The module I'm thinking shouldn't be that difficult (I think). Basically, the XML database just lists the files that are to be loaded .. no longer than 130 records in each database ..

    If I can only find a way to call swfs from this database and also have the flexibility to search the XML databases, that would be awesome.

    If this module was going online, for sure I would have used PHP or SQL, but this isn't the case ..

    Any ideas?

  4. #4
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    What's in the XML files and what are you trying to do with it? It's easy enough to load an XML file and search it in Flash. If you happen to pull the name of an SWF file out of the XML file you can just call loadMovie to load that SWF, no problems there? Maybe I'm missing the problem?

  5. #5
    Member
    Join Date
    Jul 2003
    Location
    Brampton, ONT
    Posts
    50

    update and clarification

    I've been working on the XML database and I've succeeded.

    This is what I have done so far:

    1> I have managed to search, find and list the elements of the database onto flash ... now I want to push this into overdrive.

    My AS code is like below:
    Code:
    stop();
    
    //asfunction to load pics from the text files.
    function loadPics(movie){
    	movieHolder.loadMovie(movie);
    	movieHolder._alpha = 75;
    }
    //asfunction to go to a different frame from text files
    function goFrame(frame){
    	gotoAndPlay(frame);
    }
    
    //we load a background pic and reduce its alpha value.
    _root.presentationHolder.loadMovie("presentation_back.jpg");
    _root.presentationHolder._alpha = 50;
    
    //these are radiobuttons of group1, where we define the label
    chapter1.setLabel("Chapter 1");
    chapter24.setLabel("Chapter 24");
    chapter26.setLabel("Chapter 26");
    chapter27.setLabel("Chapter 27");
    chapter30.setLabel("Chapter 30");
    
    //these are radiobuttons of group2, where we define the label
    load_all.setLabel("load_all");
    special.setLabel("special");
    
    //here we set the properties of the main textfield and the listbox
    InstanceName_0.backgroundColor = 0xFEFFD9;
    myList.setStyleProperty("shadow", 0x000000); 
    myList.setSize(150, 100);
    myList.setStyleProperty("background", 0xFEFFD9); 
    
    //this is the main function for the "submit" button
    function searchSite() {
    	movieHolder.unloadMovie();//the movieholder for jpgs is unloaded every time
    	myList.removeAll();//the listbox is made empty
    	InstanceName_0.text = "";//the textfield is cleared
    	//we now ask which xml file we want to upload using radiobuttons of group1
    	if (group1.getValue() == "chapter1") {//the value is equal to the label here
    		findchapter1();
    	} else if (group1.getValue() == "chapter24") {
    		findChapter24();					
    	}else if (group1.getValue() == "chapter26") {
    		findChapter26();					
    	}else if (group1.getValue() == "chapter27") {
    		findChapter27();					
    	}else if (group1.getValue() == "chapter30") {
    		findChapter30();					
    	}
    }
    //uploading xml files, for details see earlier tutorials
    function findchapter1(){
    	presentation = new XML();
    	presentation.load("xml/chapter1.xml");
    	presentation.ignoreWhite = true;
    	presentation.onLoad = findPresentation;
    	findPresentation();
    }
    
    function findchapter24(){
    	presentation = new XML();
    	presentation.load("xml/chapter24.xml");
    	presentation.ignoreWhite = true;
    	presentation.onLoad = findPresentation;
    	findPresentation();
    }
    
    function findchapter26(){
    	presentation = new XML();
    	presentation.load("xml/chapter26.xml");
    	presentation.ignoreWhite = true;
    	presentation.onLoad = findPresentation;
    	findPresentation();
    }
    
    function findchapter27(){
    	presentation = new XML();
    	presentation.load("xml/chapter27.xml");
    	presentation.ignoreWhite = true;
    	presentation.onLoad = findPresentation;
    	findPresentation();
    }
    
    function findchapter30(){
    	presentation = new XML();
    	presentation.load("xml/chapter30.xml");
    	presentation.ignoreWhite = true;
    	presentation.onLoad = findPresentation;
    	findPresentation();
    }
    
    function findpresentationsOver30(){
    	presentation = new XML();
    	presentation.load("presentations1.xml");
    	presentation.ignoreWhite = true;
    	presentation.onLoad = findpresentations;
    	findPresentation(); 
    }
    
    //here we define our basic functions, which are used to parse different xml files
    //for details see earlier tutorials
    function findPresentation() {
    	for (var count01=0; count01<= presentations.childNodes.length; count01++) {
    		if (this.childNodes[count01].nodeName.toLowerCase() == "presentation") {
    			var mypresentation01 = this.childNodes[count01];				
    		}
    	}findChapter(mypresentation01);
    }
    //accessing childnodes
    function findChapter(chapter) {
    	for (var count02=0; count02<=chapter.childNodes.length; count02++) {
    		if (chapter.childNodes[count02].nodeName.toLowerCase() == "chapter") {
    			var mypresentation02 = chapter.childNodes[count02];
    		}
    	}findChapterLoader(mypresentation02);
    }
    //accessing more childnodes
    function findChapterLoader(chapterz) {
    	for (var count03=0; count03<=chapterz.childNodes.length; count03++) {
    		if (chapterz.childNodes[count03].nodeName.toLowerCase() == "chapters") {
    			//we create variables, which we use later
    			var mypresentation03 = chapterz.childNodes[count03];
    			var loadingChapter = mypresentation03.attributes.loading;
    			//here we split our search using radiobuttons belonging to group 2.
    			if (group2.getValue() == "special") {//the value 			
    				if(loadingChapter == "special"){
    					if (check1.getValue() == true){//we go further and check if checkbox was selected
    						findSubgroup_1 (mypresentation03);							
    					}else if (check1.getValue() == false){
    						findSubgroup_2 (mypresentation03);
    					}
    				}//we do the same for the 'load all' schematics, which we did for blond
    			} else if (group2.getValue() == "load_all") {
    				if(loadingChapter == "load_all"){
    					if (check1.getValue() == true){											
    						findSubgroup_1 (mypresentation03);							
    					}else if (check1.getValue() == false){
    						findSubgroup_2 (mypresentation03);
    					}
    				}
    			}
    		}
    	}
    }
    
    //function to load the text for the main textfield.
    //"presentationdescription" equals the attribute "ID", which holds the name for the text.
    function loadText(presentationDescription) {
    	loadVarsText = new loadVar();
    	loadVarsText.load(presentationDescription);
    	loadVarsText.onLoad = function(success) {
    		if(success) {
    			InstanceName_0.html = true;//we want to use html in the text.
    			InstanceName_0.htmlText = this.myText;//"myText" is var name in the text document.
    		}else{
    			trace("not loaded");
    		}
    	}
    }
    //now we have to access all the childnodes, here for those which contain the attribute
    //name "bookmark"
    function findSubgroup_1 (subGroup) { 
    	for (var count04=0; count04 <= subGroup.childNodes.length; count04++) {	
    		mypresentation04 = subGroup.childNodes[count04];		
    		//"count04" will count all childnodes starting from 0.
    		//only the nodes with a positive match will be listed.	
    		if(count04>=0 && mypresentation04.attributes.reminderz == "bookmark" && mypresentation04 != undefined){
    			presentationName = mypresentation04.attributes.name;//name attribute
    			//the var* presentationDescription holds the nodeValue of the firstChild of each node
    			presentationDescription=mypresentation04.firstChild.nodeValue;
    			//but when there is no nodeValue and therefore firstChild is undefined, then
    			//this means we have an attribute "ID" and presentationDescription will hold the
    			//attribute ID, which is a text document.
    			if (presentationDescription == undefined){
    				presentationDescription=mypresentation04.attributes.ID;
    			}//here we now execute the function for the listbox with the 
    			//two arguments "presentationName", which holds the name of the presentations
    			//and "presentationDescription", which holds a nodeValue or the ID attribute.
    			choosepresentation(presentationName,presentationDescription);						
    		}		
    	}
    }
    
    //this is essentially the same as in the previous chapter, except we will list
    //all childnodes of a particular parent node.
    function findSubgroup_2 (subGroup) {
    	for (var count04=0; count04 <= subGroup.childNodes.length; count04++) {		
    		mypresentation04 = subGroup.childNodes[count04];
    		if(count04>=0 && mypresentation04 != undefined){
    			presentationName = mypresentation04.attributes.name;
    			presentationDescription=mypresentation04.firstChild.nodeValue;
    			if (presentationDescription == undefined){
    				presentationDescription=mypresentation04.attributes.ID;
    			}
    			choosepresentation(presentationName,presentationDescription);
    		}
    	}
    }
    
    //listbox changeHandler function
    function chooseMenu(myList) {
    	movieHolder.unloadMovie();//we clear the movieholder, every time a listbox
    	//item is selected. "presentationDescription" is the value for each item.
    	presentationDescription = myList.getValue();
    	if (myList.getValue()!=undefined){
    		//we either execute the loadVars function(see above) or show the nodeValue
    		//in the main textfield "InstanceName_0.text" depending on what 
    		//presentationDescription will hold. When you execute this with "Test Movie", 
    		//there will be a complain, because either hasn't been found but that does not
    		//matter for execution of the movie itself.
    		loadText(presentationDescription);
    		InstanceName_0.text = presentationDescription;
    	}
    }
    
    //function for the listbox
    function choosepresentation(presentation,description){
    	//this script defines the item "presentation", which is "presentationName" and its
    	//value description, which is "presentationDescription". All items will be listed.
    	myList.addItem(presentation,description);
    	//this will execute the above function and only one item be selected.
    	chooseMenu(myList);
    	myList.setChangeHandler("chooseMenu");
    }
    //______________________

    My XML database looks like this:

    Code:
    <?xml version="1.0"?>
        <presentation>
          <chapter name="chapter one">
            <chapters loading="load_all">
              <schematic name="FTSF100100a_001" reminderz="bookmark">
                FTSF100100a_001
              </schematic>
              <schematic name="FTSF100100a_002" reminderz="bookmark">
                FTSF100100a_002
              </schematic>
              <schematic name="FTSF100100a_003">
                FTSF100100a_003
              </schematic>
            </chapters>
            <chapters loading="special">
              <schematic name="FTSF100100a_006">
                FTSF100100a_006
              </schematic>
            </chapters>
          </chapter>
        </presentation>
    Hope this all makes sense coz my next step is a doozie!!

    continued next

  6. #6
    Member
    Join Date
    Jul 2003
    Location
    Brampton, ONT
    Posts
    50

    continued...

    I have over 20+ databases that have over 100 schematics in them. What to do now is after the user finds the chapter and selects the schematic, I would like to have it load the refering SWF maybe incorporate this tag

    >>Images XML database

    Code:
    <IMAGES>
      <imageNode jpegURL="Chapt. 01 - Operations Information/FTSF100100a_001.swf">schematic one</imageNode>
    <!-- Each <imageNode> statement following the firstChild is referenced as the nextSibling -->
      <imageNode jpegURL="Chapt. 01 - Operations Information/FTSF100100a_002.swf">Schematic two.</imageNode>
    </IMAGES>
    >>And call it like this AS:
    Code:
    images_xml = new XML();
    images_xml.onLoad = startImageViewer;
    images_xml.load("xml/images.xml");
    images_xml.ignoreWhite = true;
    //
    // 	Show the first image and intialize variables
    function startImageViewer(success) {
    	if (success == true) {
    			rootNode = images_xml.firstChild;
    // 	'totalImages' is the variable name set to correspond with the the dynamic text instance of 'totalImages'
    			totalImages = rootNode.childNodes.length;
    // 	[ totalImages = rootNode.childNodes.length; ] gets the total number of childNodes (total number of image and text files) in your .xml document
    			firstImageNode = rootNode.firstChild;
    			currentImageNode = firstImageNode;
    // 	'currentIndex' is the variable name set to correspond with the dynamic text instance of 'currentIndex'
    			currentIndex = 1;
    // 	[ currentIndex = 1; ] sets the viewer to play the first childNode (first image and text file) in your .xml document  		
    			updateImage(firstImageNode);
    	}
    }
    //
    // 	Updates the current image with new image and text 
    function updateImage(newImageNode) {
    // 	'imagePath' is the variable name set to correspond with the .jpeg file name located in your .xml document  		
    	imagePath = newImageNode.attributes.jpegURL;
    // 	'imageText' is the variable name for the instance 'textArea' 	
    	imageText = newImageNode.firstChild.nodeValue;
    // 	'targetClip' is the instance name for the movie clip 'imageArea', this is where all your image files from your .xml document are loaded
    	targetClip.loadMovie(imagePath);
    // 	IMPORTANT : RESCALING THE SIZE OF THE 'imageArea' MOVIE CLIP WILL AFFECT THE ORIGNAL SIZE OF WHATEVER IMAGE YOU HAVE IN YOUR IMAGES FOLDER	
    }
    //
    /* 	Event handlers for 'Next image' and 'Previous image' buttons.
    	These statements allows flash to advance or go back	to the next childNode
    	(next image and text) in your .xml document.
    	
    	The Property (.nextSibling;) evaluates the XML object and references the next sibling
    	in the parent node's child list. This method returns null if the node does not
    	have a next sibling node. This is a read-only property and cannot be used to
    	manipulate child nodes.
    */
    next_btn.onRelease = function() {
    	nextImageNode = currentImageNode.nextSibling;
    	if (nextImageNode == null) {
    		break;
    	} else {
    		currentIndex++;
    		updateImage(nextImageNode);
    		currentImageNode = nextImageNode;
    	}
    };
    //
    // 	Event handler for 'Previous image' button
    back_btn.onRelease = function() {
    	previousImageNode = currentImageNode.previousSibling;
    	if (previousImageNode == null) {
    		break;
    	} else {
    		currentIndex--;
    		currentImageNode = previousImageNode;
    		updateImage(previousImageNode);
    	}
    };
    But I'd like this to be dynamic - meaning - when the user chooses from the text box the schematic they would like to load ... the images database should work with the listing database ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center