PDA

View Full Version : Why do I get '{' expected


tally622
02-17-2008, 02:09 PM
Good Morning All. I am brand new to ActionScript so I KNOW this is a stupid question. I have been charged with creating flash banners for my boss. I have done one and added a URLRequest just fine. When I tried to add same script to next banner I keep getting a '{' expected error. I have worked on this for 2 hours now and simply cannot see any difference between the 2. Why would 1 work and the other not?

travikk
02-17-2008, 02:31 PM
Give us some code so we can help you.

tally622
02-17-2008, 02:45 PM
Thanks a lot for responding. The code is short so I'll post it here. The first one that worked is:

var link:URLRequest = new

URLRequest("http://www.salesquenchers.com");
var colorA:ColorTransform = new ColorTransform;
hidden_mc.addEventListener(MouseEvent.CLICK, oneClick);

function oneClick(event:MouseEvent):void
{
navigateToURL(link);
colorA.alphaOffset = -255;
hidden_mc.transform.colorTransform = colorA;

inv_btn.scaleX = 200;
inv_btn.scaleY = 200;
hidden_mc.buttonMode = false
}


hidden_mc.enabled = true
hidden_mc.buttonMode = true
var colorT:ColorTransform = new ColorTransform;

inv_btn.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void
{
colorT.alphaOffset = 100;
hidden_mc.transform.colorTransform = colorT;
hidden_mc.buttonMode = true
inv_btn.scaleX = .02;
inv_btn.scaleY = .02;
}


The second, I simply created the new button and movie clip (hidden_mc) and copy and pasted the code. When I started getting the error I reduced it to this:

var link:URLRequest = new URLRequest("http://www.salesquenchers.com");
inv_btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void
{
navigateToURL(link);
}

I get same error.


EDIT
Please put Actionscript code in [ as ] [ /as ] tags (without spaces)

panel
02-17-2008, 03:11 PM
Code is ok, so problem have to be elsewere

coreman2200
02-17-2008, 03:51 PM
Yeah the code's fine. Maybe you have a closing bracket for say a package or something and maybe forgot the opening one? Or maybe a class. Whatever the case its 'outside' of this provided code where you're having the problem. Good luck on the search - in my worst of times I've spent at least an hour looking through code to find, at the brink of total maniacal insanity and violent destructive rage, that it had been some stupid, small problem like the ones I detailed above. lol. But I'm amazingly mentally hilarious, for a programmer.. :)

tally622
02-17-2008, 05:57 PM
There is no other code. Do you think that it could be in the version saved in or some other obvious thing I'm not seeing? Is there a way to send the 2 .fla files for someone to look at? This is very frustrating getting one to work perfectly and then get stopped dead by such a silly thing.

panel
02-18-2008, 09:58 AM
You can zip them and attach here

i am kaleb
01-11-2010, 06:53 PM
I have a similar situation occuring. I'm wanting to export a twitter widget i've implented into a flash site and continue to recieve the compiler error:

Symbol=Twitter Widget, Layer=layer 5, frame=1, line 5 -- '{' expected -- function processXML(e:Event):void

Here is the code:

var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("http://twitter.com/statuses/user_timeline.xml?screen_name=nickslandl"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void
{
var myXML:XML = new XML(e.target.data);

tweet_1.text = myXML.status[0].text;
tweet_2.text = myXML.status[1].text;
tweet_3.text = myXML.status[2].text;
}


Any ideas? I've read about classes and the like and can't quite connect the dots. Any help would be appreciated. Thanks!

wvxvw
01-11-2010, 06:59 PM
1. don't use autoformat feature of Flash IDE, id does more harm then good.
2. don't use Flash IDE for coding, it wasn't intended to do that... :)
Your code should actually look more like this:
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.addEventListener(Event.COMPLETE, completeHandler);
myXMLLoader.load(new URLRequest(
"http://twitter.com/statuses/user_timeline.xml?screen_name=nickslandl"));

function completeHandler(event:Event):void
{
var myXML:XMLList = XML(myXMLLoader.data).status;

tweet_1.text = myXML.text[0].toString();
tweet_2.text = myXML.text[1].toString();
tweet_3.text = myXML.text[2].toString();
}

i am kaleb
01-11-2010, 07:35 PM
I'm not familiar with Flash IDE or it's Autoformat function. I'm using CS3 to build the widget, and was scouring the web and came across some source code that it looked like it might do what i wanted. I just copied and pasted the code and tried a few things before posting here.

I am still getting the same error after implmenting the code you provided. I also changed it a bit to access a .php file, but that shouldn't effect the compiler errors i am getting.

Any other ideas?

wvxvw
01-11-2010, 08:01 PM
IDE stands for Integrated Development Environment, this means that Flash CS3 falls under this category as well as Flash CS4 or Flash MX etc. It is used to differentiate from the Flash platform, where SWF format, FLV / F4V etc would fall under the same category as well.
I've tried compiling this code with Flash CS3 and it compiles perfectly well, no errors. So, look for the errors elsewhere.
In general it is a bad practice to put code anywhere on the timeline - you should write the code in classes, which are plain text files with .as extension.

i am kaleb
01-11-2010, 08:05 PM
Excellent. Does the class (.as) file need to be saved anywhere specific on the server, in relation to the .swf? Sounds like I need to do more reading into classes. Thanks again!

i am kaleb
01-11-2010, 08:10 PM
....and do i need to reference this class I've created? How does the .swf know to read the class file? In this case, I've copied the code to my text editor and saved it as twitter.as. Is that all?