A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [F8]How to access functions in external swfs and pass them variables?

  1. #1
    Senior Member
    Join Date
    Mar 2007
    Posts
    133

    [F8]How to access functions in external swfs and pass them variables?

    Hi,

    Im very close to the end of building my site, although i have one major issue i have to deal with.

    Basically the homepage has links to different work in the portfolio and i need each of these to link to the correct sections of the external portfolio.swf (without having to create new swfs for each possibility...). I have a function called loadPortfolioSelection(); in the portfolio.swf:

    function loadPortfolioSelection(selectedWork:String):Void {
    currentPage = selectedWork;
    this[selectedWork + "_mc"].gotoAndStop(7);
    this[selectedWork + "Text_mc"].gotoAndPlay("_in");
    mcLoader.loadClip(this[selectedWork+".swf"], this[selectedWork + "Loader_mc"]);
    trace("It worked");
    }



    My problem is that i am unable to call this function from the main swf and pass it a variable.

    My code inside home.swf is

    portfolioLoader_mc.loadPortfolioSelection(page);

    *The page variable holds the value i want (tested it with a trace(page))


    I can't even trigger the trace command in loadPortfolioSelection(); so its obviously not executing this function. I've tried a number of different ways to execute the function but i just can't get it working.


    Any help would be greatly appreciated.

  2. #2
    Senior Member
    Join Date
    Mar 2007
    Posts
    133
    Ok i’ve done a bit of an update but im still having problems. I’ll try and outline everything.

    Home.swf (relevant code):
    PHP Code:
    box2Hit_mc.onRelease = function () {
        
    removeCurrentPage(currentPage); //remove current page
        
    currentPage "portfolio";
        
    loadExternalSwf("portfolio");
        
    portfolioLoader_mc.loadPortfolioSelection("work2"); //show the work 2 in the portfolio
    }

    function 
    loadExternalSwf(page:String):Void {
        
    mcLoader.loadClip(page ".swf",page "Loader_mc");
        
    this[page "_mc"].gotoAndStop(7);
        
    extAnimMask_mc.visible false;

    Portfolio.swf (relevant code):
    PHP Code:
    function loadPortfolioSelection(selectedWork:String):Void {
        
    currentPage selectedWork;
        
    loadProject(selectedWork);
        
    trace("loadPortfolioSelection Executed");
    }

    function 
    loadProject(page:String):Void {
        for(var 
    i=1i<=numProjectsi++){
            if(
    currentPage == "work"+i){
                
    _root["work"+i+"Loader_mc"]["mainMask_mc"].gotoAndPlay("_out");
                
    _root["work"+i+"Loader_mc"]["viewPrevious_mc"].gotoAndPlay("_off");
                
    _root["work"+i+"Loader_mc"]["viewNext_mc"].gotoAndPlay("_off");
                
    _root["work"+i+"Loader_mc"].clearAnimInterval();
                
    trace(i);
            }
        }    
        
    this[currentPage "_mc"].gotoAndPlay("_out");         //remove highlighting of nav text
        
    this[currentPage "Text_mc"].gotoAndPlay("_out");   //remove text
        
    mcLoader.loadClip(page ".swf",page "Loader_mc"); //load new project
        
    this[page "Text_mc"].gotoAndPlay("_in");             //bring new text in
        
    this[page "_mc"].gotoAndStop(7);                     //highlight nav text
        
    currentPage page;

    Now here’s the problem. On the first box2Hit_mc.onRelease() the portfolio section loads but the work is not selected and using the trace command i found that loadPortfolioSelection() is not being called at all. However, if i go back to the homepage and click the same box again, loadPortfolioSelection() is executed (trace shows up), but the work is not shown, so loadProject is not working correctly. I then test loadProject using trace (inside the if statement in the for loop) and it shows the correct value has been passed from home.swf to portfolio.swf (page = “work2”). However for some reason the work2.swf never loads, the new text does not come in, and the nav wont highlight (so basically nothing changes).

    This has been annoying me for a while now. I would be thankful for any help anyone can provide. Thx

  3. #3
    Senior Member
    Join Date
    Mar 2007
    Posts
    133
    ^bump

  4. #4
    Senior Member
    Join Date
    Mar 2007
    Posts
    133
    ^bump... I know it's a difficult problem, but surely someone knows how to fix this?

  5. #5
    Member
    Join Date
    Nov 2003
    Location
    Ontario, Canada
    Posts
    80
    I am having teh same problem

    I have a MAIN_mc.swf with a loader component in it called mainLoader

    I load other swf's into the load but I want to send them commnad

    in HTML_mc.swf there is a function called show HTML

    I want to be able to click on a button in MAIN_mc and have ti execute teh function in HTML_mc

    kinda like
    Code:
    Actions.loadHTML = function(docPath){
        loadMovie("HTML_mc.swf",_root.mainLoader);
        _root.mainLoader.showHTML(docPath);
    };
    should mainLoader inherit teh objects and functions of the swf loaded?

  6. #6
    Senior Member
    Join Date
    Mar 2007
    Posts
    133
    Gemione i think you'd be better off using a movieclip to load the swf rather than a loader component. It gives you more control over it. Then you could access it like homeMcLoader_mc.showHTML();

    Im getting closer to figuring my situation out. I've tried a few things in other swfs that seem to working (with a similar principle). I'll post my solution when i work it out. Seems like nobody else has a clue...

  7. #7
    Member
    Join Date
    Nov 2003
    Location
    Ontario, Canada
    Posts
    80
    Maybe im dumb but I couldnt get it to load. I made a workaround though

    Teh Paretn movie clip, Wehn I execute a function that I wanted to control the client MC I sent the avriable to a textfile, then the client would load that variable when it loaded. Its messy and definatly inefficient but It works.

    Swf->Command->php-txt->swf

    oh well.

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