SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AS3 and Insanity

    I am having the worst problems. I am working on my final project for class and I thought it would be a great idea to add a Flash slideshow.... Notsomuch. I have managed to get the code to where it actually stops the .swf from looping, but I have a whole new error when I click on my back and next buttons to nav through the images. The new error is:

    TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@293d4089 to flash.display.MovieClip.
    at Untitled_fla::MainTimeline/clickHandler2()

    So, now that I want to curl up in the fetal position and die, can someone help me with this code?

    import flash.events.MouseEvent;
    import flash.events.Event;

    stop();
    next_btn.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(event:Event):void
    {
    MovieClip(parent).nextFrame();
    }


    last_btn.addEventListener(MouseEvent.CLICK, clickHandler2);
    function clickHandler2(event:MouseEvent):void
    {
    MovieClip(parent).prevFrame();
    }


    I have a single file and in that is all of the images. I haven't ever coded anything like this before and I am feeling quite stupid not being able to figure it out.

    I would appreciate any help at all. I have 24 hours to get this stupid thing done and I still have so much work to do....and a job. Over my head, here.

  2. #2
    SitePoint Guru [Paul Ferrie]'s Avatar
    Join Date
    Oct 2007
    Location
    Glasgow, Scotland, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do a trace on MovieClip(parent) and see what it comes back as.
    Code:
    trace(MovieClip(parent))
    .:To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Glasgow Flasher
    bringmadeleinehome.com

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by [Paul Ferrie] View Post
    Do a trace on MovieClip(parent) and see what it comes back as.
    Code:
    trace(MovieClip(parent))
    I will give that a shot... I work an hour from my house and that's where I am now (lucky me), so I have to wait till tonight. do I put that right into my code or at the end? I appreciate the help....I definitely am in need.

  4. #4
    SitePoint Guru [Paul Ferrie]'s Avatar
    Join Date
    Oct 2007
    Location
    Glasgow, Scotland, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For testing purpose's replace your code with that below
    Code:
    import flash.events.MouseEvent;
    import flash.events.Event;
    
    stop();
    next_btn.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(event:Event):void
    {
     //MovieClip(parent).nextFrame();
    trace(MovieClip(parent))
    }
     
    
    last_btn.addEventListener(MouseEvent.CLICK, clickHandler2);
    function clickHandler2(event:MouseEvent):void
    {
        //MovieClip(parent).prevFrame();
    trace(MovieClip(parent))
    }
    .:To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Glasgow Flasher
    bringmadeleinehome.com

  5. #5
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by [Paul Ferrie] View Post
    For testing purpose's replace your code with that below
    Code:
    import flash.events.MouseEvent;
    import flash.events.Event;
    
    stop();
    next_btn.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(event:Event):void
    {
     //MovieClip(parent).nextFrame();
    trace(MovieClip(parent))
    }
     
    
    last_btn.addEventListener(MouseEvent.CLICK, clickHandler2);
    function clickHandler2(event:MouseEvent):void
    {
        //MovieClip(parent).prevFrame();
    trace(MovieClip(parent))
    }
    OK....I will definitely give that a shot and see what happens. When I did the thing to start with, the instructions had me create my first symbol (after the background was complete) and then double click on that, opening the edit thing, then I added more frames with more images... I believe the instructions were in AS2 instead of AS3, so that got me jacked up to start with. Then I did a little research to find the right code for AS3. So I have the main part, then all of the images are inside that other area (forgive me for not knowing the best way to put this...terminology wise) and that other area is called content_mc... So I figured that I would have to put that somewhere, but when I tried, it still didn't work, so I am assuming that I put it in wrong. I will try your code when I get home and see what happens.

    Thinking I need to get out of here early today....Boss-man may not be happy.

  6. #6
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did it and am still getting the same error. Too weird. Maybe I need to find another tutorial for this? LOL

  7. #7
    SitePoint Guru [Paul Ferrie]'s Avatar
    Join Date
    Oct 2007
    Location
    Glasgow, Scotland, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the fla?
    .:To me AS is like LEGO, Only for the big Kids :.
    - Site - Blog - Glasgow Flasher
    bringmadeleinehome.com

  8. #8
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have you tried removing MovieClip(parent) and just calling nextFrame?

    it looks like you are trying to cast the Stage as a MovieClip which doesn't seem to be working so well.. also, you might have a scope issue.

    in AS2, the actionscript would be in the clicked button's scope but in AS3 it applies to the main timeline (stage). tryjust doing:

    Code:

    import flash.events.MouseEvent;
    import flash.events.Event;

    stop();
    next_btn.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(event:Event):void
    {
    nextFrame();
    }


    last_btn.addEventListener(MouseEvent.CLICK, clickHandler2);
    function clickHandler2(event:MouseEvent):void
    {
    prevFrame();
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •