Senior Member
[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.
Flashmatics
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
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 .
Senior Member
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
Senior Member
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
Flashmatics
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
Senior Member
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");
}
}
Flashmatics
where are you actually calling the function btnEnabler ..i dont see a call btnEnabler()
Senior Member
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?
Flashmatics
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
Senior Member
right on!!!!! thanks for all you help dood
Flashmatics
np your welcome ..im off to sleep now lol!!!
Flash Video Moderator
Flashmatics
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");
}
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width