A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Loading Var from Javascript to External Swfs

  1. #1
    Animator
    Join Date
    Jan 2001
    Location
    Dubai
    Posts
    200

    Unhappy Loading Var from Javascript to External Swfs

    Hi

    I am loading one variable from javascript to one main swf file which does have 2 more links to other 2 external swf files, i want to use the same var to be transfered to those 2 files when they are loaded, how to do it any help would be much appreciated.

    This is teh javascript in the header:

    function CountryCode(){
    document.getElementById('Spotlight_en_gb').SetVari able("ccode", "SU");
    }

    This script is triggered onLoad when the page loads.

    One dynamic text box var name is ccode and instance name countrychk is taking the values and action accordingly, other two files need the same var to use but on LoadMovie they dont get teh value.

    Here are the links:
    1.

    on (release) {
    unloadMovie(1);
    loadMovie("Movies.swf", 1);
    }


    2.

    on (release) {
    unloadMovie(1);
    loadMovie("Series.swf", 1);
    }


    I have tried adding it like that:

    on (release) {
    unloadMovie(1);
    loadMovie("Movies.swf?ccode="+_root.countrychk.tex t+"", 1);
    }


    But that doesnt worked out.

    Please help

    Fahad.
    [email protected]
    I won't change directions and i won't change my mind, How much difference does it made?

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    You'll have to have the second loaded SWF, draw back to the main SWF to obtain the variable. To pass values from SWF to SWF, you'd usually use FlashVar, but since you're not using HTML, your best bet would be to get the value(s) from the main timeline.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    Hey Samac,

    I dont think he is opening any new SWF. If you give a good look at the code then u can determine that he is using loadMovie which loads swf inside a movie clip or level as you mention in your code.

    So Mr. Bhatti,

    If you wana access any variable in the main swf from the loaded swf then in the loaded swf please try to trace following and check if you get the value:

    PHP Code:
    trace(_root.countrychk); 
    I think this should not disappoint us. Hope this helps!
    Last edited by vinayak.kadam; 04-01-2009 at 12:32 AM. Reason: Spelling mistake!
    As ever,
    Vinayak Kadam

  4. #4
    Animator
    Join Date
    Jan 2001
    Location
    Dubai
    Posts
    200
    Thanks for the replies, but is it the right way to send the variable to external swfs?

    on (release) {
    unloadMovie(1);
    loadMovie("Movies.swf?ccode="+_root.countrychk.text+"", 1);
    }

    All movies have the dynamic text box with the var name ccode.
    [email protected]
    I won't change directions and i won't change my mind, How much difference does it made?

  5. #5
    Senior Member vinayak.kadam's Avatar
    Join Date
    Oct 2006
    Location
    gotoAndPlay("Pune");
    Posts
    831
    Well,

    I think we need to be bit clear here.

    1. You are not trying to open any external swf in any new window.
    2. When you use loadMovie it loads an external swf into your current movie.

    In above case you need not need to transfer any variable to externally loaded swf, instead from the external swf you can access a variable from main swf. The syntax which you gave is valid when you load open any swf via HTML in altogather a new window.
    As ever,
    Vinayak Kadam

  6. #6
    Animator
    Join Date
    Jan 2001
    Location
    Dubai
    Posts
    200
    Yes all external swfs are opening in my current movie, and the Var i get from javascript which is generated in the html onLoad gets first into the main swf first and then when calling other 2 swfs it get transferred to other swfs.

    I have tried the :

    loadMovieNum("Series.swf?ccode="+_root.countrychk. text+"", 1);

    for getting it in the external swf and that seems working, if you see any issue in that please let me know.

    Thanks
    Fahad
    [email protected]
    I won't change directions and i won't change my mind, How much difference does it made?

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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center