A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Calling a function

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Posts
    10

    Calling a function

    I have a very basic question. I have a custom class called caurina. I've imported the class and it works great. What i did is use that as a function called slide().

    What I would like to do is make that function play when a button is pressed. I can't seem to find out how to do this anywhere. I am using as3 in CS4.

    Summary: When btn is pressed go play function slide()
    Thanks!

  2. #2
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    You need to add some event listeners. The button will call a function when it is clicked, then from there you can call the slide() function.

    PHP Code:
    button.addEventListener(MouseEvent.CLICKbuttonClicked)

    function 
    buttonClicked (e:MouseEvent):void {
        
    slide();

    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  3. #3
    Junior Member
    Join Date
    Apr 2007
    Posts
    10
    Thanks for your response.

    This is what I tried, and got this error message.
    Argument count mismatch on test2_fla::MainTimeline/slide(). Expected 0, got 1


    Here is my code:
    import caurina.transitions.*;


    function slide() {
    Tweener.addTween(test, {x:89, y:170, time:2});

    }

    button2.addEventListener(MouseEvent.CLICK, slide)



    What's wrong with the addeventlistener im trying to use???

    Thanks!

  4. #4
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    Whenever a function is called because of an event, the method being called (ie. slide() ) MUST have ONE argument, which must match the event type...


    Change it to
    PHP Code:
    import caurina.transitions.*;

    function 
    slide(e:MouseEvent) {
        
    Tweener.addTween(test, {x:89y:170time:2} );
    }

    button2.addEventListener(MouseEvent.CLICKslide
    ktu[k-two]
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.


  5. #5
    Junior Member
    Join Date
    Apr 2007
    Posts
    10
    I got it working, thanks so much for you help!

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