A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [AS3]Call function outside of a class file

  1. #1
    wierd
    Join Date
    Sep 2008
    Posts
    46

    [AS3]Call function outside of a class file

    hello there,

    I like to call a function that is outside of the class file.

    for example

    main.fla
    Code:
    function callmepls(){
     trace("yes");
    }
    Calling.as
    Code:
    package{
     public class Calling{
      callmepls();
      public function Calling(){
      }
     }
    }

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You need to create another class and make the function public.

    package
    {
    public class Calling
    {
    public function Calling ():void
    {
    var cm:Called=new Called();
    cm.callmepls ();
    }
    }
    }


    package
    {
    public class Called
    {
    public function Called ():void
    {
    }
    public function callmepls ():void
    {
    trace ("yes");
    }
    }
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    wierd
    Join Date
    Sep 2008
    Posts
    46
    hello cancerinform,

    thanks for answering.

    Are there no other way? I mean like dispatch an Event in the class file to the main stage and add there an EventListener which opens a function.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Why make it complicated?
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    wierd
    Join Date
    Sep 2008
    Posts
    46
    k I give you the big picture.

    In the first frame I like to load all my xml-data in a unique global variable. I believe those data then are called value object or something.

    So the only why to assign something to a global variable in a function can only be done in a class file right?

    What I like to do is I want to call a function when the class is finished assigning the xml-data to a global variable.

  6. #6
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Put your entire XML-data logic into a class. Typically, this would just be the document class. You could set the entire document class to be public, and then even public static for just that function. Depending on the situation.

  7. #7
    wierd
    Join Date
    Sep 2008
    Posts
    46
    Quote Originally Posted by MyFriendIsATaco
    Put your entire XML-data logic into a class. Typically, this would just be the document class. You could set the entire document class to be public, and then even public static for just that function. Depending on the situation.
    Thanks. Document Class is the keyword I needed.

  8. #8
    LukewarmSteak - Jordan Embury
    Join Date
    Jul 2009
    Location
    Toronto Ontario Canada
    Posts
    24
    update??
    solved??

    i'm trying to finish my preloader's post animation sequence - when it reaches its last frame - i want the document class to initiate "addChild" objects - either by calling a function from the preloader's postanimation class or by passing a variable to the document class to check to see if i can continue with adding objects to the stage...

  9. #9
    wierd
    Join Date
    Sep 2008
    Posts
    46
    hi LukewarmSteak

    Yeah my problem was actually solved. I forgot to mark it.

    And to your problem:

    I had the same problem too when I wanted to create a working preloader.

    This is how I did it:

    My preloader has a "Playing Out Animation" and when it's finished I dispatch an Event (in my case a customevent) to the preloader class file. It calls a function which removes the eventlistener when it's finished it dispatch the Event Complete to the document class.
    At this point you can call your addChild function.

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