A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS3 makes me cry

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    5

    AS3 makes me cry

    Ok, I've recently started to learn AS3 and I'm found out very quickly that it's a completely new ball game. Arrrrrrrghhhhhh Understatement

    Can anyone help advance my learning a little in regards to this problem?

    I have a few buttons on my main.swf which i want to use to load external movies. The problem I am having is that in AS2 I could just attach the AS to the button, but it seems in AS3 this is not the case?

    How can I reference the specific buttons and from the AS? Considering that I am using 1 piece of code slightly modified for each button.

    Code:
    var imageRequest:URLRequest = new URLRequest("movie2.swf");
    car imageLoader:Loader = new Loader();
    imageLoader.load(imageRequest);
    addChild(imageLoader);
    
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    
    function onComplete(event:Event):void
    {
    event.target.content.slidingpages.x -= 100;
    }
    Any help would be great as I'm at a complete loss on this. Thanks in Advance

  2. #2
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Location
    Planet Earth
    Posts
    312
    If I understand you correctly, you are just having problems making your buttons work?

    Lets say a button is on the stage called 'about_btn' - it will load the about page

    in the actions panel for that frame your code would look like this

    import flash.events.MouseEvent;
    about_btn.addEventListener(MouseEvent.CLICK, aboutButtonClicked);
    function aboutButtonClicked (e:MouseEvent):void {
    trace("about button was clicked");
    }
    first we import the MouseEvent, we must do this so the flash player knows what a MouseEvent is.

    Next, we add an event listener to the about_btn. Notice referencing the items on the stage is exactly like AS2: stage.child.anotherchild

    After the type of event we listen for we tell it the function to call.
    In this function you can set the url for the swf to load, and load the file.

    you will probably need a loader for each page...

    Hope that helps
    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
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    A simple way is to place your Loader objects in MovieClips. Since MCs are dynamic you can add variables like this:

    mc.myURL="movie.swf";

    You get reference over

    var mcNew:MovieClip = event.currentTarget.content.parent.parent as MovieClip;
    trace(mcNew.myURL);
    - The right of the People to create Flash movies shall not be infringed. -

  4. #4
    Junior Member
    Join Date
    Jan 2008
    Posts
    5
    Thanks for everything folks, got this sorted now a few headaches later.

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