Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-03-2012, 10:37 PM   PM User | #1
Code_Impaired
New to the CF scene

 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Code_Impaired is an unknown quantity at this point
Unhappy Scene 1, Layer 'actions', Frame 1, Line 94 1083: Syntax error: else is unexpected.

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;
}
Code_Impaired is offline   Reply With Quote
Old 04-04-2012, 06:38 PM   PM User | #2
adaminaudio
New Coder

 
Join Date: Jan 2012
Location: Columbus, Ohio, U.S.A
Posts: 41
Thanks: 0
Thanked 8 Times in 8 Posts
adaminaudio is an unknown quantity at this point
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:

Code:
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.
adaminaudio is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:17 PM.


Advertisement
Log in to turn off these ads.