A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Baffled: "{ expected"

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    24

    Baffled: "{ expected"

    Hi,

    I'm getting baffled with a project I'm trying to build which has code for buttons to link out to different websites on one frame, and a news reader on a second frame.

    I know the news reader works when it's put into a standalone project.
    The code is:

    PHP Code:
    stop();     
    // Set up variables
    var mxnaURL:String "http://www.bbc.co.uk";
    var 
    mxnaRequest:URLRequest = new URLRequest(mxnaURL);
    var 
    mxnaLoader:URLLoader = new URLLoader();
    var 
    myTimer:Timer = new Timer(2000);//set up timer

            



    // Assign listeners for downloading feed
    mxnaLoader.addEventListener(Event.COMPLETEfeedDownloadedHandler);
    // Error listeners
    mxnaLoader.addEventListener(IOErrorEvent.IO_ERRORfeedDownloadError);
    mxnaLoader.addEventListener(SecurityErrorEvent.SECURITY_ERRORfeedDownloadError);

    // Event handlers
    // Called when feed has completely downloaded
    function feedDownloadedHandler(event:Event):void {
        
        
    // use a try-catch block in case
        // xml parsing fails
        
    try {
        
            
    // convert the loaded text into XML
            
    var mxnaXML:XML XML(mxnaLoader.data);
            
            
    // if XML succeeded (no error)
            // show it in the text field 
            
    renderFeedXML(mxnaXML);
            
        }catch(
    error:Error){
            
    trace("Error parsing XML: "+error);
        }
        
    }
    // Called if feed download fails
    function feedDownloadError(event:Event):void {
        
    trace("Error during download: "+event);
    }


    // Functions
    // Writes each feed item to the screen
    function renderFeedXML(feed:XML):void {
        
        
    // get default namespace for feed
        
    var defaultNs:Namespace = new Namespace("http://purl.org/rss/1.0/");
        
    // set default namespace to make referencing easier
        
    default xml namespace = defaultNs;

        
    // clear screen text
        
    mxnaText.text "";

        
    // write each Feed item to the screen
        // looping through the XMLList with for each
        
    var items:XMLList feed.item;
        for 
    each (var item:XML in items){
            
            
    myTimer.addEventListener(TimerEvent.TIMERfadeout) ;
            
    myTimer.start();
            
    renderFeedItem(item); //call in feed item

            
            

            
            
        
    }
    }
            
    // Writes a single feed item to the screen
    function renderFeedItem(item:XML):void {
        
        
    // namespaces
        
    var rdf:Namespace = new Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
        var 
    dc:Namespace = new Namespace("http://purl.org/dc/elements/1.1/");
        var 
    defaultNs:Namespace = new Namespace("http://purl.org/rss/1.0/");
        
        
    // set default namespace to make referencing easier

        
    default xml namespace = new Namespace("http://purl.org/rss/1.0/");

        
    // parse date string [YYYY-MM-DD]
        
    var date:String item.dc::date.text().substring(010);

        
    // write other feed content to text using HTML
        
    mxnaText.htmlText += "<u><b><a href=\""+item.@rdf::about+"\">"+item.title+"</a></b></u><br />";
        
    //scroll text
        
        
    }

    // Download XML feed. Once loaded, the
    // parsing and displaying process will start
    try {
        
    mxnaLoader.load(mxnaRequest);
        
    mxnaText.text "Loading...";
    }catch(
    error:Error){
        
    trace("Error during load: "+error);
    }

        
    function 
    fadeout(event:Event):void {
        
    myTimer.stop();
            if (
    mxnaText.alpha>0) {
                
    mxnaText.alpha -= 0.1;
            } else {
                
                
    mxnaText.alpha 1;
                
    myTimer.removeEventListener(TimerEvent.TIMERfadeout) ;
                return
            } 
    }

    Similarly, I'm trying to replace some simple AS2 versions of button.onRelease function that I originally used has now been replaced with:

    PHP Code:
    bbc_btn.addEventListener(MouseEvent.CLICKonMouseClick);

    function 
    onMouseClick (e:MouseEvent):void
    {
    var 
    request:URLRequest = new URLRequest("http://www.bbc.co.uk");
    navigateToURL(request,"_blank");

    However, when it compiles, all I get are errors like '{' expected' attached to the lines in the code:


    function feedDownloadedHandler(event:Event):void {

    and

    function onMouseClick (e:MouseEvent):void{

    Can anyone help me get to the bottom of the problem?

    Thank you.

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    according to your pasted code, fadeout() is missing a closing bracket '}'

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