Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 10 of 10

Thread: Linking SWF files

  1. #1

    Pallete Linking SWF files

    I made several SWF files and I am trying to link them together but I am not sure how, let me give you a short description to help illustrate my problem.

    Right now I have 3 applications, and a main page. All 4 SWFs were compiled from different FLA files. The main page has 3 buttons that links to all 3 of the SWF files. When I tried to do a URLRequest-URLLoader method to load the swf files, I realised I had to compile all the MovieClips of the 3 applications within the main.fla for them to actually work when you do URLLoader to load them(or it will throw a missing file error). I couldn't move all the graphical assets into main.fla as there are many replica names of different graphics from all 3 different application fla files.

    Is there a way to still link up different SWF files without the need for all the graphics to be in one similar FLA file? or is there a way to remedy my situation without having to rename all the MovieClips?
    Last edited by DjTeddySpin; July 25th, 2011 at 10:34 PM.

  2. #2
    Bump~ Still interested to know.

  3. #3
    Ok I found the answer. The error that I was getting was the null object error and I immediately assumed that it has something to do with MovieClips not correctly named or the Class was not found. I was wrong, the error was simple, it does not recognise this:

    stage.stageWidth
    Probably something to do with stage.

  4. #4
    You can't access stage within a Class until that Class object has been added to the Display List (meaning added to the stage or added to another object that has been added to the stage.) More here.

    You'll probably want to use the ADDED_TO_STAGE event within your child SWFs, when that event is fired, then you can set up your Object knowing you can access the stage and it's properties.

  5. #5
    Thanks for the reply, I have a new question. Now that I have loaded my swf file, it is suppose to play to the end and then remove itself. I tried using:

    this.parent.removeChild(this);

    and it works, but I want to inform the main.swf of the removal thus I wrote something like:

    this.parent.manager('remove');

    manager is a public function within my main.swf, but this code doesn't seem to work. So is there still a way to inform the main.swf whenever I remove one of the 3 applications?

    (the trigger for removal lies within the 3application swf, since I am suppose to remove only after they end the application. So it has to speak to main.swf in some way to inform of the removal)
    Last edited by DjTeddySpin; July 28th, 2011 at 12:02 AM.

  6. #6
    Can you post the code from Main that loads your swf? One simple way is to dispatch an event from the child, but you need to set Main to listen to the event. I can probably get you in the right direction if you post that code.

  7. #7
    *and so the file path is sent into the function*

    Code:
    private function loadSWF(path:String):void {
    	var req:URLRequest = new URLRequest();
    	req.url = path;
    
    	swfLoader = new Loader();
    	setUpListeners(swfLoader.contentLoaderInfo);
    
    	swfLoader.load(req);
    }
    
    
    private function setUpListeners(dispatcher:IEventDispatcher):void {
    	dispatcher.addEventListener(Event.COMPLETE, addSWF);
    }
    
    
    private function addSWF(event:Event):void {
    	event.target.removeEventListener(Event.COMPLETE, addSWF);
    
    	swfContent = event.target.content;
    	this.addChild(swfContent);
    }

  8. #8
    PHP Code:
        private function loadSWF(path:String):void {
            var 
    req:URLRequest = new URLRequest();
            
    req.url path;

            
    swfLoader = new Loader();
            
    setUpListeners(swfLoader.contentLoaderInfo);

            
    swfLoader.load(req);
        }


        private function 
    setUpListeners(dispatcher:IEventDispatcher):void {
            
    dispatcher.addEventListener(Event.COMPLETEaddSWF);
        }


        private function 
    addSWF(event:Event):void {
            
    event.target.removeEventListener(Event.COMPLETEaddSWF);

            
    swfContent event.target.content;

            
    // *************************************
            // Add your listener to the target.content property.
            // You can use whatever string you'd like:
            
    swfContent.addEventListener("CHILD_EVENT"onChildEvent);
            
    this.addChild(swfContent);
        }
        
        private function 
    onChildEvent(e:Event):void {
            
    trace("CHILD_EVENT captured...")
        }
        
        
    //********************************
        // Within the main timeline in your child SWF, you can dispatch this event from any frame — again, doing it this way, it will
        // only be heard if it's dispatched from the main timline. 
        
    dispatchEvent(new Event("CHILD_EVENT")); 

  9. #9
    Wow thanks I will try that out once I am back in the office. What I did to bypass that issue is by adding an enterframe listener onto a Holder that checks for numChildren. I would add the swfContent onto that holder. So when the swf removes itself(when the application is completed) from the Holder, the numChildren will fall to 0, and thats when I startup my main.swf again. But I know how enterFrame slows down the application unnecessarily in this case.

    But thanks really, if I manage to get your suggestion to work it's really going to help me a bunch! I will update again soon

  10. #10
    Amazing, it works! Thanks! Now I have to go read up on the cool custom event!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012