A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [F8] Calling MovieClip function... Imposible?

  1. #1
    Junior Member
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    26

    [F8] Calling MovieClip function... Imposible?

    Hi,
    I have a MovieClip in my Scene, In this MovieClip I have a Layer with ActionScript that contain one Function named "Hellow"...

    I'm tring to call the "Hellow" function from an ActionScript layer in the main Scene... and it's not working... WHY???
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Nov 2006
    Posts
    15
    put the function above any actionscript.

    what's hapening at your fla... first the AS function is called.. and after that it is defined. keep all your functions on the first layer of your scene (so no defining functions within MC's) and you'll be fine.

    Code:
    function Hellow() {
    	trace("HEEELLLOOOW");
    }
    
    Hellow();
    will work, because you define it before you call it...

  3. #3
    Junior Member
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    26
    but I want the function within the MC!

    I want to have a MovieClip that contain some animation, other MovieClips, and functions to operate them...

    I can't call those functions from outside???



    Lets say that I have this "Products container" MovieClip, this MC include a nice graphic container with scroll bar, title, etc. within this MC there's a "Load_From_XML" function that will attach "Item" MovieClips...

    I can't call this function from the main time line????
    Last edited by gilamran; 11-20-2006 at 05:41 AM.

  4. #4
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    Yes you can, but you are running into problems of timing...

    Your code is correct, but the function is not initiated by the time you call it. Try putting the call to HelloMC.Hellow(); on frame 2 of the main timeline instead and you will see what I mean. It is possible to get around the timing problem using initclip etc. ,however, this is neither the best nor the easiest way to go about it!

    Keeping code in different library clips makes debugging a nightmarish job of detective work and searching. It also promotes duplication of code and other very bad practice that make maintaining a piece of software nigh on impossible.

    That said, you have clearly (and correctly) recognised the benefit of assigning specific code to specific clips which will make debugging and development easier because you can build and test indivdual elements in isolation.

    SO...

    Spend the few minutes it takes to learn how to write a simple class and then assign it to a library item. That way, you isolate your code into text files that are easily searched and debugged. You get the benefits of reusable and easy to maintain code. You get to begin thinking in a proper OOP direction and you will find you can do a lot more very easily.

    Remember, classes are easy, classes are your friend.

    For a (very) basic example of a class applied to a movie clip, have a look at: http://www.gdcsoft.com/SimpleMan/SimpleMan.zip
    http://www.gdcsoft.com/SimpleMan/SimpleMan.html

    Better still, buy Moock's book on Essential ActionScript 2.0 and read it once from cover to cover.

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