A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [RESOLVED] confusing creating MC with an array

  1. #1
    Senior Member
    Join Date
    Jun 2001
    Posts
    116

    resolved [RESOLVED] confusing creating MC with an array

    I make a search function its working but like I want it, because it display the results from the xml but its text only and i cant click on it what I want is
    create a movieclip based on each results from the xml array so i can address each movieclip with an onclick event ... I am making myself clear ?

    Well that doesnt make sense because how i know which mc represent which result word ???

    anyway is there any other way to accomplish this basically i want that when you start searching the matching words appears and I want to call a function when you click on any word.

    each MC need to have 2 textfield ,one for the word and one for the category.

    heres my AS and my XML

    PHP Code:
    function parseXML(){
       
    myXML = new XML();
       
    myXML.load("keywords2.xml");
       
    myXML.ignoreWhite true;
       
    myXML.onLoad = function(success){
          if(
    success){
             
    trace("xml loaded...");
             
    makeArray();
          }else{
             
    trace("xml load failed...");
          }
       }
    }

    function 
    makeArray(){
       
    parseWord = [];
       
    parseCat = [];
       
    parseLink = [];
       
    nodes myXML.firstChild.childNodes;
       for(
    i=0;i<nodes.length;i++){
          
    word nodes[i].attributes.word;
          
    cat nodes[i].attributes.cat;
          
    link nodes[i].attributes.link;
          
    parseWord.push(word);
          
    parseCat.push(cat);
          
    parseLink.push(link);

       }
    //trace(parseWord);
    //trace(parseLink);
    ////////////////////////////////////////////////////////////////////////////////////////////
    function search(query){
        
    trace(query)
        
    _root.holder.s_results.text ""
        
    _root.holder.s_title.text ""
        
    var oneFound false
        
    for(0i<_root.parseWord.lengthi++){
            if(
    _root.parseWord[i].indexOf(query) != -1){
                
                var 
    oneFound true
                _root
    .holder.s_results.text += parseWord[i]+"\r";
                
    _root.holder.s_title.text += parseCat[i]+"\n";
                
                
            }
        }
        if(
    oneFound == false){
            
    _root.holder.s_results.text "No se encontro ninguna tienda"
        
    }
        
    }
    ////////////////////////////////////////////////////////////////////////////////////////////
    s_input.onKillFocus = function(){
        
    _root.holder.gotoAndStop(1);
    }

    s_input.onChanged = function(){
        
        
    _root.holder.gotoAndStop(2);
        
    search(s_input.text);
                   
      }


    holder.onRelease = function(){
        
        
    trace("you click grande");

    }
    }
    parseXML(); 

    XML
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <keywords>
    		<sKey word= "walmart" cat="Tiendas por Departamento" link="AS"/>
    		<sKey word= "sears" cat="Tiendas por Departamento" link="AS"/>
    		<sKey word= "kmart" cat="Tiendas por Departamento" link="AS"/>
    		<sKey word= "jc penney" cat="Tiendas por Departamento" link="AS"/>
    		<sKey word= "pueblo" cat="Supermecados" link="AS"/>
    		<sKey word= "grande" cat="Supermercados" link="AS"/>
    		<sKey word= "amigo" cat="Supermercados" link="AS"/>
    		<sKey word= "econo" cat="Supermercados" link="AS"/>	
    		<sKey word= "walgreens" cat="Farmacias" link="AS"/>
    		<sKey word= "amal" cat="Farmacias" link="AS"/>
    		<sKey word= "eckerd" cat="Farmacias" link="AS"/>
    		<sKey word= "kmart" cat="Farmacias" link="AS"/>
    		<sKey word= "costco" cat="Farmacias" link="AS"/>
    	
    	
    
    </keywords>
    using Flash CS3

    P.S.

    why Flashkit forum doesnt have AS wrap tags ???
    I have seen those i think in ActionScript forums.

    anyway Thanks in advanced for your help !!!!!!

  2. #2
    Senior Member
    Join Date
    Jun 2001
    Posts
    116
    BTW the tag in the xml file that said link= its there just in case i was thinking its possible to put there the function i want to call and invoke it from the movie ?

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe you can adapt this to what you are trying to do...

    Wrap each dynamic text field inside a unique movie clip.
    Code:
    	function search(query) {
    		trace(query);
    		_root.holder.resultsMC.s_results.text = "";
    		_root.holder.titleMC.s_title.text = "";
    		var oneFound = false;
    		for (i = 0; i < _root.parseWord.length; i++) {
    			if (_root.parseWord[i].indexOf(query) != -1) {
    				var oneFound = true;
    				_root.holder.resultsMC.s_results.text += parseWord[i] + "\r";
    				_root.holder.titleMC.s_title.text += parseCat[i] + "\n";
    			}
    		}
    		if (oneFound == false) {
    			_root.holder.resultsMC.s_results.text = "No se encontro ninguna tienda";
    		}
    	}
    	//////////////////////////////////////////////////////////////////////////////////////////// 
    	s_input.onKillFocus = function() {
    		_root.holder.gotoAndStop(1);
    	};
    	s_input.onChanged = function() {
    		_root.holder.gotoAndStop(2);
    		search(s_input.text);
    	};
    	holder.onRelease = function() {
    		if (this.resultsMC.hitTest(_xmouse, _ymouse, false)) {
    			trace("you clicked " + this.resultsMC.s_results.text);
    		} else if (this.titleMC.hitTest(_xmouse, _ymouse, false)) {
    			trace("you clicked " + this.titleMC.s_title.text);
    		}
    	};
    }

  4. #4
    Senior Member
    Join Date
    Jun 2001
    Posts
    116
    its works great in the sense of if you want to trace what you click but if i dont filter the search until the end it will trace the whole list, I explain if i type W the results give me walmart and walgreens if i click either of those it trace walmart and walgreens.
    How can I make that it create a movieclip for each result that way you can click on it individually doesnt matter how many results are on display..

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe you can adapt this to what you are trying to do...

    Instead of wrapping in extra movie clips... using an embedded font and htmlText (instead of text).
    Code:
    showSel = function (args) {
    	var tmpArray = args.split(",");
    	trace(tmpArray[0]);
    	trace(tmpArray[1]);
    };
    function search(query) {
    	trace(query);
    	_root.holder.s_results.htmlText = "";
    	_root.holder.s_title.htmlText = "";
    	var oneFound = false;
    	for (i = 0; i < _root.parseWord.length; i++) {
    		if (_root.parseWord[i].indexOf(query) != -1) {
    			var oneFound = true;
    			_root.holder.s_results.htmlText += "<a href=\"asfunction:_root.showSel,1," + parseWord[i] + "\">" + parseWord[i] + "</a><br>";
    			_root.holder.s_title.htmlText += "<a href=\"asfunction:_root.showSel,2," + parseCat[i] + "\">" + parseCat[i] + "</a><br>";
    		}
    	}
    	if (oneFound == false) {
    		_root.holder.s_results.htmlText = "No se encontro ninguna tienda";
    	}
    }
    //////////////////////////////////////////////////////////////////////////////////////////// 
    s_input.onKillFocus = function() {
    	_root.holder.gotoAndStop(1);
    };
    s_input.onChanged = function() {
    	_root.holder.gotoAndStop(2);
    	search(s_input.text);
    };

  6. #6
    Senior Member
    Join Date
    Jun 2001
    Posts
    116
    thanks a lot I will try it, when i get home ...

    what am trying to accomplish its something like the apple website search function...
    I didnt try your last code yet but... thats why I was asking about the MC's duplications because the keywords have differents classifications and I would like to display each matching search word in its own classification box and each subsequent matching in its own classification box each under the first one...creating like a list of boxes with its own classifications and matching words.

  7. #7
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Sorry, I didn't understand before, but I think this is more in line with what you are trying to accomplish.

    AS2 code
    Code:
    function parseXML() {
    	myXML = new XML();
    	myXML.load("keywords.xml");
    	myXML.ignoreWhite = true;
    	myXML.onLoad = function(success) {
    		if (success) {
    			trace("xml loaded...");
    			makeArray();
    		} else {
    			trace("xml load failed...");
    		}
    	};
    }
    function makeArray() {
    	parseWord = [];
    	parseCat = [];
    	parseLink = [];
    	nodes = myXML.firstChild.childNodes;
    	for (i = 0; i < nodes.length; i++) {
    		word = nodes[i].attributes.word;
    		cat = nodes[i].attributes.cat;
    		link = nodes[i].attributes.link;
    		parseWord.push(word);
    		parseCat.push(cat);
    		parseLink.push(link);
    	}
    	//trace(parseWord); 
    	//trace(parseLink); 
    	//////////////////////////////////////////////////////////////////////////////////////////// 
    	showSel = function (args) {
    		var tmpArray = args.split(",");
    		if (tmpArray[0] == 1) {
    			trace("Clicked Category: " + tmpArray[1]);
    		} else {
    			trace("Clicked Word: " + tmpArray[1]);
    		}
    	};
    	chkIt = function (lst, cat, res) {
    		var isExist = false;
    		for (j in lst) {
    			if (lst[j] == cat) {
    				lst[cat].ary.push(res);
    				isExist = true;
    				break;
    			}
    		}
    		if (!isExist) {
    			lst[cat] = new Object(cat);
    			lst[cat].ary = new Array();
    			lst[cat].ary.push(res);
    		}
    	};
    	function search(query) {
    		trace(query);
    		var obList = new Object();
    		var tArray = new Array();
    		_root.holder.s_results.htmlText = "";
    		var oneFound = false;
    		for (i = 0; i < _root.parseWord.length; i++) {
    			if (_root.parseWord[i].indexOf(query) != -1) {
    				var oneFound = true;
    				chkIt(obList, parseCat[i], parseWord[i]);
    			}
    		}
    		if (oneFound == false) {
    			_root.holder.s_results.htmlText = "No se encontro ninguna tienda";
    		} else {
    			for (k in obList) {
    				_root.holder.s_results.htmlText += "<a href=\"asfunction:_root.showSel,1," + k + "\">" + k + "</a><br>";
    				for (n in obList[k].ary) {
    					_root.holder.s_results.htmlText += "<li><a href=\"asfunction:_root.showSel,2," + obList[k].ary[n] + "\">" + obList[k].ary[n] + "</a></li>";
    				}
    			}
    		}
    	}
    	//////////////////////////////////////////////////////////////////////////////////////////// 
    	s_input.onKillFocus = function() {
    		_root.holder.gotoAndStop(1);
    	};
    	s_input.onChanged = function() {
    		_root.holder.gotoAndStop(2);
    		search(s_input.text);
    	};
    }
    parseXML();
    xml test file
    PHP Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <keywords>
        <sKey word= "walmart" cat="Tiendas por Departamento" link="AS"/>
        <sKey word= "wally" cat="Tiendas por Departamento" link="AS"/>
        <sKey word= "sears" cat="Tiendas por Departamento" link="AS"/>
        <sKey word= "kmart" cat="Tiendas por Departamento" link="AS"/>
        <sKey word= "jc penney" cat="Tiendas por Departamento" link="AS"/>
        <sKey word= "pueblo" cat="Supermecados" link="AS"/>
        <sKey word= "grande" cat="Supermercados" link="AS"/>
        <sKey word= "amigo" cat="Supermercados" link="AS"/>
        <sKey word= "econo" cat="Supermercados" link="AS"/>    
        <sKey word= "walgreens" cat="Farmacias" link="AS"/>
        <sKey word= "amal" cat="Farmacias" link="AS"/>
        <sKey word= "eckerd" cat="Farmacias" link="AS"/>
        <sKey word= "kmart" cat="Farmacias" link="AS"/>
        <sKey word= "costco" cat="Farmacias" link="AS"/>
    </keywords>
    HTH

  8. #8
    Senior Member
    Join Date
    Jun 2001
    Posts
    116
    wow !!! man, getting a little complicated ahh ?? I'm not too familiarized with Array's methods .


    but hey thanks a lot you have been a great help and the only one too !!

  9. #9
    Senior Member
    Join Date
    Jun 2001
    Posts
    116
    you're a genius, now am trying to digest the code a little so i can modified it a little in terms of aesthetics's ...

    so the parseCat be in bold and stuff like that !!

    other thing is how i control what is click in the list, right know if i click anything in the list the onkillfocus function is call !!

    it would be possible that I can fill the link= tag in the xml to say something like link="goWalgreen" goWalgreen been a function in the flash and then parse that to the flash file and call it when that parseWord is click ??

    anyway here i send a copy of the xml and fla , but maybe you already have it

    test fla and xml file

  10. #10
    :
    Join Date
    Dec 2002
    Posts
    3,518
    This should fix the problem with the onFocusKill problem and shows how you can also access the link from the xml (replace the trace with your function.)
    Code:
    showSel = function (args) {
    	var tmpArray = args.split(",");
    	if (tmpArray[0] == 1) {
    		trace("Clicked Category: " + tmpArray[1]);
    	} else {
    		trace("Clicked Word: " + tmpArray[1] + " Link: " + tmpArray[2]);
    	}
    	_root.holder.gotoAndStop(1);
    };
    chkIt = function (lst, cat, res, lnk) {
    	var isExist = false;
    	for (j in lst) {
    		if (lst[j] == cat) {
    			lst[cat].ary.push([res, lnk]);
    			isExist = true;
    			break;
    		}
    	}
    	if (!isExist) {
    		lst[cat] = new Object(cat);
    		lst[cat].ary = new Array();
    		lst[cat].ary.push([res, lnk]);
    	}
    };
    function search(query) {
    	trace(query);
    	var obList = new Object();
    	var tArray = new Array();
    	_root.holder.s_results.htmlText = "";
    	var oneFound = false;
    	for (i = 0; i < _root.parseWord.length; i++) {
    		if (_root.parseWord[i].indexOf(query) != -1) {
    			var oneFound = true;
    			chkIt(obList, parseCat[i], parseWord[i], parseLink[i]);
    		}
    	}
    	if (oneFound == false) {
    		_root.holder.s_results.htmlText = "No se encontro ninguna tienda";
    	} else {
    		for (k in obList) {
    			_root.holder.s_results.htmlText += "<a href=\"asfunction:_root.showSel,1," + k + "\">" + k + "</a><br>";
    			for (n in obList[k].ary) {
    				_root.holder.s_results.htmlText += "<li><a href=\"asfunction:_root.showSel,2," + obList[k].ary[n][0] + "," + obList[k].ary[n][1] + "\">" + obList[k].ary[n][0] + "</a></li>";
    			}
    		}
    	}
    }
    //////////////////////////////////////////////////////////////////////////////////////////// 
    s_input.onKillFocus = function(evt) {
    	s_input.text = "";
    	if (evt != _root.holder.s_results) {
    		_root.holder.gotoAndStop(1);
    	}
    };
    I've only got MX2004 and can't access your file, I had just built a dummy for testing. Best of luck, I'm out of here for the week end!

  11. #11
    Senior Member
    Join Date
    Jun 2001
    Posts
    116
    I've only got MX2004 and can't access your file, I had just built a dummy for testing. Best of luck, I'm out of here for the week end!
    thats ok !! but thanks a lot man, really thanks for your help and have a nice week end !!

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