...

View Full Version : Scene 1, Layer 'actions', Frame 1, Line 94 1083: Syntax error: else is unexpected.



Code_Impaired
04-03-2012, 11:37 PM
Scene 1, Layer 'actions', Frame 1, Line 94 1083: Syntax error: else is unexpected.

I am getting this error and I don't quite know why. I am a total beginner with ActionScript so I thought this would be a great place to get some help.

Code:
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;

//create container to hold images
var container:Sprite = new Sprite();

//create Array for buttons and images
var btnMenu:Array = new Array();
var images:Array = new Array["images/image1", "images/image2", "images/image3", "images/image4", "images/image5"];

//create transparent bar across the bottom where buttons will set
var menuBg:Shape = new Shape();
menuBg.graphics.beginFill(0x666666, .5);
menuBg.graphics.drawRect(0, 650, 1024, 30);
menuBg.graphics.endFill();
addChild(container);
//add menu bar to display list
addChild(menuBg);

//variable for counting
var totalLinks:int = 5;

//create menu
for (var i:int=0; i<totalLinks;i++) {
//create shapes for buttons
var btnBg:Shape = new Shape();
btnBg.graphics.lineStyle(2, 0xFFFFFF, .7, true);
btnBg.graphics.beginFill(0xFFFFF8, .5);
btnBg.graphics.drawRect(0, 0, 10, 8);
btnBg.graphics.endFill();
//create new instance of buttons each time loop runs
//buttons will be encased within Sprite
var myBtn:Sprite = new Sprite();
//give new button unique instance name
myBtn.name = "image" + (i+1).toString();
//set Sprite to act as a button
myBtn.buttonMode = true;
//add new button to display list
addChild(myBtn);
//position button on a horizontal line
myBtn.y=660;
myBtn.x=400+(i*30);

//add background shape to button display
myBtn.addChild(btnBg);

//add Event Listeners to buttons
myBtn.addEventListener(MouseEvent.CLICK, btnHandler);
myBtn.addEventListener(MouseEvent.ROLL_OVER, btnHandler);
myBtn.addEventListener(MouseEvent.ROLL_OUT, btnHandler);
//add buttons to btnMenu Array
btnMenu.push(myBtn);
}

//create temporary Loader to hold the first image
//so we don't start with a blank page
var tempLoader:Loader = new Loader();
tempLoader.load(new URLRequest("images/image1"));
container.addChild(tempLoader);

//multiple event function for buttons
function btnHandler(event:MouseEvent):void {
//check to see if mouse click event
if (event.type==MouseEvent.CLICK) {
//use loop to associate correct URL with each btn clicked
for (var i:int=0;i<totalLinks;i++) {
//find which btn has been pressed by its index (i) in btnArray
if (event.target==btnMenu[i])
//create new Loader and set properties
var loader:Loader = new Loader();
loader.alpha = 0;
loader.x = 1024;

//load image based on index of current btn
loader.load(new URLRequest(images[i]));
//add loader to container
container.addChild(loader);

//tween the alpha and blur of image
TweenLite.to(loader, 1.5, {alpha:1, x:0, ease:Elastic.easeInOut});
TweenMax.to(loader, 0, {blurFilter:{blurX:30}});
TweenMax.to(loader, 2, {blurFilter:{blurX:0}});

}

}
trace(event.target.name + "was clicked");
} //check to see if this is a roll over event
else if(event.type==MouseEvent.ROLL_OVER){
//change the alpha of the button to create a roll over effect
event.target.alpha=.7;
}//check to see if this is a ROLL_OUT event
else if(event.type==MouseEvent.ROLL_OUT){
//change alpha back to 100%
event.target.alpha = 1;
}

adaminaudio
04-04-2012, 07:38 PM
hmmm,


looks as if it's your syntax. I haven't posted this into an AS3 file but you may have an 'else if' statment inside of brackets. The brackets are there to group the statements in a function (sorry, you probably already know that). Your function should look something like this with the 'else if' statements outside of brackets:


myFunction():void
{
if('something')
{

}
else if('something else')
{

}
else if('something else again')
{

}
else('anything else')
{

}


}so... Clean up your code a bit, keep your functions to around 10 lines if possible, and make sure your brackets match up. It will be more readable to you and others and make life easier. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum