A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: External .swfs

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1

    External .swfs

    Hi All.
    I’m new to Flash and really enjoying the challenges and rewards of working with this software.

    But recently I ran into a problem that’s been giving my headaches for the past few weeks,
    What I’m after is a website that will load and unload external .swfs from the navigation bar which I’ve achieved and this works well, The problem is when I put a button in one of the externally loaded .swf to load another no luck.

    I have attached a scaled down version of the site I’m working towards, my problem begins at my Gallery page which has the buttons on and id like to link these buttons to the pages of the same name and after also have Previous and Next function to go back and forward between the gallery pages.

    var Xpos:Number = 0;
    var Ypos:Number = 0;
    var swf:MovieClip;
    var loader:Loader = new Loader();
    var defaultSWF:URLRequest = new URLRequest("swfs/HOME.swf");

    loader.load(defaultSWF);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);

    // Button function
    function btnClick(event:MouseEvent):void {

    removeChild(loader);
    var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
    loader.load(newSWFRequest);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);
    }
    // Button listeners
    HOME.addEventListener(MouseEvent.CLICK, btnClick);
    ABOUT.addEventListener(MouseEvent.CLICK, btnClick);
    GALLERY.addEventListener(MouseEvent.CLICK, btnClick);
    CONTACT.addEventListener(MouseEvent.CLICK, btnClick);
    GALLERY1.addEventListener(MouseEvent.CLICK, btnClick); (This the line I’m having the problem with I receive 1120: Access of undefined property GALLERY1.)


    Any help and comments will be much appreciated and thanks in advance.
    Attached Files Attached Files

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    i can't open your file since i'm on CS3, but it's pretty safe to assume that GALLERY1 doesn't exist at the moment this code is executed.

    second, if you want to communicate with a containing swiff from a loaded swiff, use the event management system.

    add a listener to your loader, and dispatch the event from anywhere within your loadee.

    e.g.,

    PHP Code:
    loader.addEventListener("myEvent"myHandlerfalse0true);
    function 
    myHandler(event:Event):void{
      
    trace("howdy");
      
    // do whatever you want here

    and from any loaded swiff:

    PHP Code:
    var e:Event = new Event("myEvent"true);
    dispatchEvent(e); 
    i used string literals here for simplicity and brevity; best practice would be to implement a custom event class and use string constants.

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