A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: simple question! Please Help!

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    66

    simple question! Please Help!

    Hi guys,

    I have a flash file that loads external images randomly onto the stage!
    that part works just fine.

    I have placed the code for loading images on the second frame of the flash file.

    what I want to do is to create a button on the second frame so when the users click on it the flash file will go back on the first frame. (basically a Back Button).

    I did create a button and it will go back to the first frame once its clicked....
    However the image that loaded on the second frame will stay on the stage when the flash file's gone back to the first frame.

    I need to remove the image loaded on the second frame as well when it has gone back to the first frame!!

    This is my code:

    Actionscript Code:
    stop();

    var pHeight:Number = 346;
    var pWidth:Number = 263;

    var listLoader:URLLoader = new URLLoader( new URLRequest("filelist.xml") );
    var picLoader:Loader = new Loader();

    listLoader.addEventListener(Event.COMPLETE, gotList);

    function gotList(evt:Event):void {
        var xmlData:XML = XML(listLoader.data);
        var numImages:Number = xmlData.pix.length();
       
        var stImage:String = xmlData.pix[Math.floor(numImages*Math.random())].toString();
       
        picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, gotPic);
        picLoader.load( new URLRequest(stImage) );
       
        listLoader.removeEventListener(Event.COMPLETE, gotList);
    }

    function gotPic(evt:Event):void {
        var thisBmp:Bitmap = Bitmap(evt.target.content);
        thisBmp.x = 28;
        thisBmp.y = 72;
        var thisWidth:Number = thisBmp.width;
        var thisHeight:Number = thisBmp.height;
       
        thisBmp.scaleX = pWidth/thisWidth;
        thisBmp.scaleY = pHeight/thisHeight;
        addChild(thisBmp);
       
        picLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, gotPic);
    }

    //////////////Back button function//////////////////

    btn_back.addEventListener(MouseEvent.MOUSE_DOWN, nClick2);

    //--- next button timeline control ---\\
    function nClick2(event:MouseEvent):void{
    gotoAndPlay(1);
    }

    any help will be much appreciated.

    Thanks in advance.
    Last edited by PalNatter; 06-11-2011 at 09:05 AM.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    try this:

    function nClick2(event:MouseEvent):void{
    picLoader.unloadAndStop();
    gotoAndPlay(1);
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Member
    Join Date
    Jan 2011
    Posts
    66
    Quote Originally Posted by cancerinform View Post
    try this:

    function nClick2(event:MouseEvent):void{
    picLoader.unloadAndStop();
    gotoAndPlay(1);
    }
    Thanks for the reply bud. But that didn't work!! the image is still on the first frame when I clicked on the back button.

  4. #4
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Use this: removeChild(thisBmp);

    Put the thisBmp variable outside of the function.

  5. #5
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Use this: removeChild(thisBmp);

    Put the thisBmp variable outside of the 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