A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: [F8] for loop problems

  1. #1
    Senior Member donaldparkerii's Avatar
    Join Date
    May 2005
    Location
    San Diego
    Posts
    616

    [F8] for loop problems

    when i use the following code
    Code:
    _global.suspendData = 2;
    function btnEnabler(){
    	for(var i; i = _global.suspendData; i++){
    		ch[i]_btn.enabled = true;
    		ch[i]_btn.onRelease = function(){
    			gotoAndStop("lesson");
    			_global.currCourse = "ch"+i+".swf";
    		}
    	}
    }
    I am returned the fallowing errors
    Code:
    **Error** Scene=Scene 1, layer=actions, frame=2:Line 5: Syntax error.
         		ch[i]_btn.enabled = true;
    
    **Error** Scene=Scene 1, layer=actions, frame=2:Line 6: Syntax error.
         		ch[i]_btn.onRelease = function(){
    
    Total ActionScript Errors: 2 	 Reported Errors: 2
    I am at a total loss as to what causes this.

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Code:
    _global.suspendData = 2;
    function btnEnabler(){
    	for(var i; i = _global.suspendData; i++){
    		_root["ch"+i+"_btn"].enabled = true;
    		_root["ch"+i+"_btn"].onRelease = function(){
    			gotoAndStop("lesson");
    			_global.currCourse = "ch"+i+".swf";
    		}
    	}
    }
    Last edited by silentweed; 10-12-2006 at 08:20 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    also give the movieclips an id property for use in the onRelease:

    Code:
    _global.suspendData = 2;
    function btnEnabler(){
    	for(var i =0; i = _global.suspendData; i++){
    		_root["ch"+i+"_btn"].enabled = true;
                    _root["ch"+i+"_btn"].id = i;
    		_root["ch"+i+"_btn"].onRelease = function(){
    			gotoAndStop("lesson");
    			_global.currCourse = "ch"+this.id+".swf";
    		}
    	}
    }
    Last edited by silentweed; 10-12-2006 at 08:22 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Senior Member donaldparkerii's Avatar
    Join Date
    May 2005
    Location
    San Diego
    Posts
    616
    I am not getting a output, and none of the buttons have code attached to them. I took out the enabled = true because its pretty pointless if they dont have any code at all.
    Code:
    function btnEnabler():Void{
    	for(var i = 0; i = _global.suspendData; i++){
    		trace(_root.ch[i+"_btn"])
    		_root[".ch"+i+"_btn"].onRelease = function(){
    			gotoAndStop("lesson");
    			_global.currCourse = "ch"+i+".swf";
    		}
    	}
    }
    im not even getting an output
    Attached Files Attached Files

  5. #5
    Senior Member donaldparkerii's Avatar
    Join Date
    May 2005
    Location
    San Diego
    Posts
    616
    even with trace(i); i get nothing and I also tried it the period before _root removed and added in ".ch". i also added in the id... thanks i didnt even pic that one up at first

  6. #6
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    im on mx 2004 cant opne ur file

    but it should be
    _root["ch"+i+"_btn"] not _root[".ch"+i+"_btn"] i.e take out the . before ch
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  7. #7
    Senior Member donaldparkerii's Avatar
    Join Date
    May 2005
    Location
    San Diego
    Posts
    616
    here is the code for that frame
    Code:
    stop();
    
    function btnEnabler():Void{
    	for(var i = 0; i = _global.suspendData; i++){
    		trace(i)
    		_root["ch"+i+"_btn"].id = i;
    		_root["ch"+i+"_btn"].onRelease = function(){
    			gotoAndStop("lesson");
    			_global.currCourse = "ch"+this.id+".swf";
    		}
    	}
    }
    
    function exitLMS():Void{
    	if(_global.suspendData = _global.noOfCourses){
    		ExternalInterface.call("apiCall","setValue","cmi.success_status","passed");
    		ExternalInterface.call("apiCall","setValue","cmi.completion_status","completed");
    		ExternalInterface.call("apiCall","commit");
    		ExternalInterface.call("apiCall","terminate");
    	}else{
    		ExternalInterface.call("apiCall","setValue","cmi.success_status","passed");
    		ExternalInterface.call("apiCall","setValue","cmi.completion_status","failed");
    		ExternalInterface.call("apiCall","commit");
    		ExternalInterface.call("apiCall","terminate");
    		
    	}
    	
    }

  8. #8
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    where are you actually calling the function btnEnabler ..i dont see a call btnEnabler()
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  9. #9
    Senior Member donaldparkerii's Avatar
    Join Date
    May 2005
    Location
    San Diego
    Posts
    616
    I i take off the void it still doesnt do anything. but when i call the function at the bottom of all that code, i get the error

    "a script in this movie is causing flash player to run slow...... do i want to abort?"

    shouldnt it stop after two?

  10. #10
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    aaah .. it should be for(var i = 0; i <= _global.suspendData; i++){ ..}

    dont use an equal sign or u will make it an endless loop
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  11. #11
    Senior Member donaldparkerii's Avatar
    Join Date
    May 2005
    Location
    San Diego
    Posts
    616
    right on!!!!! thanks for all you help dood

  12. #12
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    np your welcome ..im off to sleep now lol!!!
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  13. #13
    Flash Video Moderator Wheels's Avatar
    Join Date
    Dec 2000
    Location
    Minneapolis
    Posts
    1,590
    Or "==" or "<=".

  14. #14
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    the equivalence operator == would not really work. Because i starts from 0 which is NOT equivalent to 2 ..the loop would actually not even run once.. e.g the following would show no traces..

    Code:
    for(var i = 0; i == 2; i++){
    	trace("hello");
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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