A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: experts : flash 5 hates this piece of code :( why ???

  1. #1
    Senior Member
    Join Date
    Mar 2002
    Posts
    160
    hello everybody,
    i dont know what is going on , i have created this piece of code with mx (it was working all ok) , but when i tried opening with flash 5 after saving as flash 5 i have faced many problems

    1- there is an error in this piece of code , i cant find it this error is very irritating to flash 5 as it makes it un responding sometimes
    when i check syntax i find this in the output

    Line 22: 'else' encountered without matching 'if'
    else if ((_root["answer1"] != _root["correctAnswer1"] && _root["answer1"] != _root["correctAnswer_alt1"]) && (_root["answer2"] != _root["correctAnswer2"] && _root["answer2"] != _root["correctAnswer_alt2"]) && (_root["answer3"] != _root["correctAnswer3"] && _root["answer3"] != _root["correctAnswer_alt3"]) && (_root["answer4"] != _root["correctAnswer4"] && _root["answer4"] != _root["correctAnswer_alt4"]) && (_root["answer5"] != _root["correctAnswer5"] && _root["answer5"] != _root["correctAnswer_alt5"])){



    here u r the code , plz try to help
    Code:
    on (release, releaseOutside) {
    	for (k=1; k<maxanswers+1; k++) {
    		if (_root["answer"+k] == _root["correctAnswer"+k] || _root["answer"+k] == _root["correctAnswer_alt"+k]) {
    			//main if
    			//if: main if .if 2
    			if ((_root["answer1"] == _root["correctAnswer1"] || _root["answer1"] == _root["correctAnswer_alt1"]) && (_root["answer2"] == _root["correctAnswer2"] || _root["answer2"] == _root["correctAnswer_alt2"]) && (_root["answer3"] == _root["correctAnswer3"] || _root["answer3"] == _root["correctAnswer_alt3"]) && (_root["answer4"] == _root["correctAnswer4"] || _root["answer4"] == _root["correctAnswer_alt4"]) && (_root["answer5"] == _root["correctAnswer5"] || _root["answer5"] == _root["correctAnswer_alt5"])) {
    				gotoAndPlay("correctframe");
    				score++;
    				//else: main if .if 2 - else
    			} else {
    				score++;
    				gotoAndPlay("case3frame");
    			}
    			//else: main if _ else 			
    		} else {
    			//if: main if _ else .if
    			if (_root["answer1"]==""  && _root["answer2"]==""  && _root["answer3"]==""  && _root["answer4"]==""  && _root["answer5"]=="" )
    			{ _root.alertmc.gotoAndStop(2);
    			_root.alertmc._visible=true;
    			}
    			//if: main if _ else .if.else if
    		    else if ((_root["answer1"] != _root["correctAnswer1"] && _root["answer1"] != _root["correctAnswer_alt1"]) && (_root["answer2"] != _root["correctAnswer2"] && _root["answer2"] != _root["correctAnswer_alt2"]) && (_root["answer3"] != _root["correctAnswer3"] && _root["answer3"] != _root["correctAnswer_alt3"]) && (_root["answer4"] != _root["correctAnswer4"] && _root["answer4"] != _root["correctAnswer_alt4"]) && (_root["answer5"] != _root["correctAnswer5"] && _root["answer5"] != _root["correctAnswer_alt5"])){
    				gotoAndPlay("wrongframe");
    				}	
    		
    		}
    		//main if end
    	}
    	// for end
    }
    // on release end


    THANKS

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    lose the preceding comment line
    //if: main if _ else .if.else if

    or place it on the same line as the "}" before it

  3. #3
    Senior Member
    Join Date
    Mar 2002
    Posts
    160
    Originally posted by senocular
    lose the preceding comment line
    //if: main if _ else .if.else if

    or place it on the same line as the "}" before it


    THANKS A LOT
    it went ok when i deleted this part but ..
    can u tell me why is this happening ? ?

  4. #4
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    because its breaking the if/else format

    the following are acceptable formats for if statements:

    if (condition) statement;

    if (condition)
    statement;

    if (condition) statement;
    else statement;

    if (condition) statement;
    else if (condition) statement;
    else statement;

    if (condition){ statement; }

    if (condition){
    statement;
    }

    if (condition)
    {
    statement;
    }

    if (condition){
    statement;
    }else{
    statement;
    }

    if (condition){
    statement;
    }else statement;

    if (condition)
    {
    statement;
    }
    else
    {
    statement;
    }

    ... BUT something like
    if (condition)
    {
    statement;
    }
    else

    {
    statement;
    }

    will NOT work because the extra line (where you had a comment) breaks the format. You get a one line "buffer" (?) for if statements outside of any brakets used. After this, if the if statement isnt terminatd with a statement or other form of ending, it terminates itself . This is seen best with:

    if (condition)
    statement;

    you can see no brakets were used but the statement is still only run if the condition is met. In the case of

    if (condition)
    {
    statement;
    }
    else

    {
    statement;
    }

    After the closing of the first } where the else is, you are out side and code block and the 1 line buffer rule comes back into play and that empty or commented line is read by flash as the ending point of the statement and it termiates leaving you with an oddball statement in the following lines.

  5. #5
    Senior Member
    Join Date
    Mar 2002
    Posts
    160
    Originally posted by senocular
    [/B]
    THANKS A LOT senocular
    this was vvvv valuable information , i always make these mistakes in if-else and get mad
    but i am greedy some how, what about one more question about what flash5 hates ??


    Code:
    mathQuiz = new Array();
    data1=new XML();
    data1.ignoreWhite=true;
    data1.onLoad=function(){	
    	var x=0;
    	//loop through question set nodes
    	while(data1.firstChild.childNodes[x]){
    		//initiate temporary associative array to hold name value pairs
    		var temp_arr=new Array();
    		var a=0;
    		//loop through question sets and assign name value pairs to temp_arr array
    		while(data1.firstChild.childNodes[x].childNodes[a]){
    			temp_arr[data1.firstChild.childNodes[x].childNodes[a].nodeName]=
    			data1.firstChild.childNodes[x].childNodes[a].firstChild.nodeValue;
    			a++;
    		}
    		//add temp_arr to the end of math_quiz array
    		mathQuiz.push(temp_arr);
    		x++;
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    numQuestions = mathQuiz.length;
    		
    	}
    	//this part traces out the array values
    	x=0;
    	while(mathQuiz[x]){
    		var cur_vals="";
    		for(vars in mathQuiz[x]){
    			if(typeof(mathQuiz[x][vars])=="string")cur_vals+=vars+":"+mathQuiz[x][vars]+",";
    		}
    		trace("mathQuiz["+x+"] = {"+cur_vals+"};");
    		x++;
    	}
    
    		gotoAndStop("question");
    }
    data1.load("data3f5.xml");
    i used this piece of code to load a xml ( which is coming from an arabic access database )
    using flash mx or saving and publishing as flash 5 from mx
    went alll ok and i had excellent results


    but opening this in flash 5 was a surprise it didnt work at all except when i put this coming piece of code
    i dont know why ?? , i didnt write the coming piece of code and i didnt understand its objective , and i cant understand, why mine cant work alone ? ?



    Code:
    Object.version = getVersion().split(",");
    Object.majorVersion = int(substring(Object.version[0],Object.version[0].length, 1));
    Object.minorVersion = int(Object.version[2]);
    
    
    if (Object.majorVersion == 5){
    	
       XML.prototype.checkEmpty = function(text){
    		
            var max = text.length;
    		
            var empty = true;
    		
            for (var i=0;i<max;++i){
    			
              if (ord(substring(text, i+i, 1))>32){
    				
                empty = false;
    				
                 break;
    			
              }
    		
           }
    		
           return empty;
    	
          }
    	
          XML.prototype.parseXML = function(str){
    		
             this.firstChild.removeNode();
    		
             var treePtr = this;
    		
             var tags = new Array();
    		
             var textNode = null;
    		
             if (Object.minorVersion == 30){
    			
               this.status = ASnative(300, 0)(str, tags);
    		
             }else{
    			
                this.status = ASnative(300, 0)(str, tags, false);
    		
            }
    		
            if (this.status == 0){
    			
              var curr;
    			
              var i=0;
    			
              var max = tags.length;
    			
              if (this.ignoreWhite){
    				
                 while (i<max){
    					
                    curr = tags[i];
    					
                    if (curr.type == 1){
    						
                        if (curr.value == "/"+treePtr.nodeName){
    	
     	     treePtr = treePtr.parentNode;
    	
    	}else{
    							
                            treePtr.appendChild(this.createElement(curr.value));
    
    	    treePtr = treePtr.lastChild;
    	
    	    treePtr.attributes = curr.attrs;
    	
    	    if (curr.empty){
    	
    	        treePtr = treePtr.parentNode;
    	
    	    }
    						
                         }
    					
                    }else{
     if (curr.type == 3){
    
    	if (!this.checkEmpty(curr.value)){
    
    	    treePtr.appendChild(this.createTextNode(curr.value));
    
    	}
    					
                      }else{
    if (curr.type == 6){
    
    	  treePtr.appendChild(this.createTextNode(curr.value));
    
                      }else{
     if (curr.type == 4){
    
                           this.xmlDecl = curr.value;
    	
                      }else{
    
    	    this.docTypeDecl = curr.value;
                      }
    							
                 }
    						
             }
    					
          }
    					
          ++i;
    				
        }
    			
       }else{
    				
         while (i<max){
    					
           curr = tags[i];
    					
           if (curr.type == 1){
    						
              if (curr.value == "/"+treePtr.nodeName){
    	
                   treePtr = treePtr.parentNode;
    						
               }else{
    							
                   treePtr.appendChild(this.createElement(curr.value));
    	
                   treePtr = treePtr.lastChild;
    		
                   treePtr.attributes = curr.attrs;
    		
                   if (curr.empty){
    	
     	treePtr = treePtr.parentNode;
    	
                    }
    						
                }
    					
           }else{
    if (curr.type == 3 || curr.type == 6){
    
              treePtr.appendChild(this.createTextNode(curr.value));
    
          }else{
    if (curr.type == 4){
    	
               this.xmlDecl = curr.value;
    							
          }else{
    								
             this.docTypeDecl = curr.value;
    	
          }
    						
      }
    					
     }
    					
      ++i;
    				
    }
    			
    }
    		
    }
    	
    }
    
    }

    THANKS IN ADVANCE

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    F5 was the first one to handle XML at all, and it probably had some small problems (was there any ignoreWhite in F5?)
    So somewhone has just written a replacement for the builtin parseXML function to fix it.

    About bad compiler:
    Code:
    if(something) // what we are testing here...
    statement
    fails as well. It is translated into
    if(something) // nothing
    followed by unconditional statement.
    Every other ecma-type language would follow the real code structure here, rather than code formatting.

    Musicman

  7. #7
    Senior Member
    Join Date
    Mar 2002
    Posts
    160
    Originally posted by Musicman

    (was there any ignoreWhite in F5?)
    do u mean there is noway using xml with flash 5 except keeping this piece of code ??

    still i cant understand is ignore whitespace function the only missing thing ???
    what if i dont have white space ??

    PLZ HELP


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