A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: trouble with functions and navigation...oh the pain...ohh the agony...

  1. #1
    Getting Better With Time
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    54

    trouble with functions and navigation...oh the pain...ohh the agony...

    Hey there,
    I am new with ActionScript, but not new to flash. A friend told me that it is more efficient to place my actionscript in functions on frame one of the main timeline rather than having it all appear throughout the page on various buttons etc. I am trying to get a button tht loads in the main timeline to call upon a function, and then have it perform the following actions:
    a) When the mouse is released, it will send the information to a function called openServices. The code to send it here is

    //Services Button - loads the services swf
    on(release){
    _root.openServices();
    }


    Then the fuction code I have is as follows,

    //Services Button - loads the services SWF file into the main time line.
    fuction openServices(services_btn) {
    _root.createEmptyMovieClip ("infoPage_mc",_root.getNextHighestDepth());
    _root.infoPage_mc.loadMovie("hello.swf");
    _root.infoPage_mc._y=55;
    _root.infoPage_mc._x=0;
    }


    The button's instance is services_btn .

    When I try to test the movie, it states that I have a syntax error. Forgive my inability to detect this error, but I would more than appreciate some assistance. I love the idea of functions, and hope to make use of them more if I can just see a good model of one.

    Later, and Thanks,

    Greg
    ____________________________
    Greg White
    http://www.prestigeinteractive.com

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Your friend told you the right thing.

    Your function doesn't seem to take any arguments:
    code:

    function openServices() {
    _root.createEmptyMovieClip ("infoPage_mc",_root.getNextHighestDepth());
    _root.infoPage_mc.loadMovie("hello.swf");
    _root.infoPage_mc._y=55;
    _root.infoPage_mc._x=0;
    }



    If the instance name of your button is services_btn, attach this code to the main timeline as well (use the method onRelease(), don't attach code to buttons or movie clips (whenever possible)):
    code:

    services_btn.onRelease = function()
    {
    openServices();
    };



    Get used not to use _root, use relative paths instead:
    code:

    function openServices()
    {
    this.createEmptyMovieClip("infoPage_mc", this.getNextHighestDepth());
    infoPage_mc.loadMovie("hello.swf");
    infoPage_mc._y = 55;
    infoPage_mc._x = 0;
    }


  3. #3
    Getting Better With Time
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    54

    One more thing

    Hey there nunomira,
    I made the silly correction to my mispelling of function..heheh...believe it or not, I am a teacher, and it worked. I did not need to add the code you listed below to get it to work. Do you have an idea as to why this might be the case. Sorry about the lame questions.

    services_btn.onRelease = function()
    {
    openServices();
    };

    Thanks for your time,

    Greg
    Last edited by prestigeinteractive; 04-15-2005 at 11:46 PM.
    ____________________________
    Greg White
    http://www.prestigeinteractive.com

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    You're welcome.

    Yes, that was the one real problem regarding your code.

    Everything else was correct, but not following the best practices.
    Those were just two recommendations: not using _root and using methods instead of attaching code to objects.
    This last remark is also related to what your friend told you: attach all the code to the main timeline whenever you can. Don't spread it all over your movie.

  5. #5
    Getting Better With Time
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    54

    You're awesome...thanks again

    Hey again,
    Thanks a lot for your help. Do you have any cool sites you've designed or are you mainly a programmer. I'd like to check them out.
    Later,
    Greg
    ____________________________
    Greg White
    http://www.prestigeinteractive.com

  6. #6
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003

    programmer

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