A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: sending variables from one swf to another loaded swf

Hybrid View

  1. #1
    they call me the_jump... le_saut's Avatar
    Join Date
    Mar 2001
    Posts
    536
    hey hey

    I am trying to send some evaluated variables from one swf to another. Now I can do this with SWF/PHP, that's easy, so I thought I should be able to work out how to do it SWF to SWF...

    So I have a base SWF ("current.swf") which, say, asks for a persons name. The textfield variable is called name.
    Now I want to send this variable "name" to another movie that is loaded on a button press ("next.swf").
    So I do the loadMovie bit and that loads up the movie I want. I have a textfield which is called "name" so I can display the entered name.

    I've tried loading the vars to the main timeline and to a movie clip. I've jiggled round with the targets and levels also but to no avail.
    When I check the "list variables" it shows nothing being sent from "current.swf" to "next.swf"

    After reading the sparse documentation about variables in loadMovie actions in the Macromedia help section, I am led to believe though that the loadMovie action gets the variables from the loaded movie ("next.swf" in my case.)???

    Can anyone offer insight? I thought it'd be easier than sending em via a PHP script!


    le_saut

    and why doesn't Mmedia have a sendVariables action? it's counter intuitive to send variables with a loadVariable command??!

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Posts
    475
    umm...

    have u tried

    loadMovie ("your.swf?variable=value");

    i think this works - but i always used the main-timeline assign everything 3 times stuff

    You're right AS is very unintuitive... think of _totalframes and _framesloaded - shouldn't it be _loadedframes or vice versa??
    Also PHP is not very strict with the structure and definiton of function names, but i use it, maybe i like these kinds of quirks when programming - they keep me awake

    Yours
    HTD

  3. #3
    Senior Member
    Join Date
    Mar 2001
    Posts
    246
    I think you must test your movie in a html-page to use GET to transfer variables.

    If you load the new movie into a movieclip you can use:
    onClipEvent(load) {
    name=_root.name;
    }
    instead.

    regards,
    HC

  4. #4
    Junior Member
    Join Date
    Jun 2001
    Posts
    3

    inside flash

    Today i've discovered that the function loadMovie() don't put the MC there in the same frame. In theory, you must specify the variables in the next frame. For example: In the frame 5 you put the action that loads the swf and in the next frame you put all other code (variables and a play() command).

    I think it should work as done for me.

    good luck!

  5. #5
    Junior Member
    Join Date
    Jun 2001
    Posts
    8
    Hi HowardTheDuck, I am a Newbie I was wondering when I pass the variable from one movie using loadMovie ("your.swf?variable=value"); how do I get the value of the variable in your.swf? Thanks for help.

    gretz99

  6. #6

  7. #7
    Senior Member
    Join Date
    Feb 2001
    Posts
    475
    Hi gretz99

    Well my post was just an idea of how to do this, because normally the copying of values inside a movie works... basically (if used in HTML) the URL-encoded Variables reside in _root
    in your example

    ("your.swf?variable=value");

    you must access it with

    _root.variable

    Yours
    HTD

  8. #8
    they call me the_jump... le_saut's Avatar
    Join Date
    Mar 2001
    Posts
    536
    thanks for that. Altho' I do think there is a way of sending em inter-swf. I only send variables via the header as a last resort.
    PHP is excellent. I tried to explain it to some students but it went straight thru em. Maybe it was me.

    I think it was the bit about the PHP generating the HTML that got em stumped.

    I'll try the onClip event and the next frame doo-dad trick.

    Thanks for your replies.

    ls

    Originally posted by HowardTheDuck
    umm...

    have u tried

    loadMovie ("your.swf?variable=value");

    i think this works - but i always used the main-timeline assign everything 3 times stuff

    You're right AS is very unintuitive... think of _totalframes and _framesloaded - shouldn't it be _loadedframes or vice versa??
    Also PHP is not very strict with the structure and definiton of function names, but i use it, maybe i like these kinds of quirks when programming - they keep me awake

    Yours
    HTD

  9. #9
    Junior Member
    Join Date
    Jan 2001
    Posts
    24

    Post here is your answer..and yes its possible

    If I understand you correctly, becasue you did not specify. You have a base movie loading a second movie (current.swf) with a variable in it and another movie loaded on another level that has a text field in it which is basing its display off of the lower movie variable.

    (after looking through things your problem may be in trying to load the new movie onto the same level.)

    Here u go.

    For clarity purposes I am going to recreate this simply (for my sake and yours) to aid in understanding.

    INDEX.swf(the index that is going to load current.swf) also known as -> _level0
    loadMovie ("current.swf", 1);
    -----------

    CURRENT.swf (housing a variable called name) -> _level1
    ACTIONS layer (frame 1)
    _root.name = ""

    TEXTFIELD
    variable for input textfield = _root.name

    BUTTON
    on(release) {
    loadMovieNum ("next.swf", 2);
    }
    ----------

    TEXTFIELD.swf (housing textfield) -> _level2

    on the dynamic text field you would assign the variable to _level1.name

    (not _root.name because the it is looking inside of _level2 for the variable name which doent exist unless you created it. _root doesnot = _level0).

    that should do it.

    if you are wondering where a variable is and you cant find it. run a trace in the textfield_mc in a frame looking on all levels:

    trace ("_root.name = "+_root.name);
    trace ("_level0.name = "+_level0.name);
    trace ("_level1.name = "+_level1.name);
    trace ("_level2.name = "+_level2.name);
    trace ("_level3.name = "+_level3.name);

    Then when you find it...set your textfield to where the location of the variable it.

    if you want more help, email me. ubermench2001@yahoo.com
    Ill get you up and running tonight.
    Ben Schmidtke
    Macromedia Training Instructor/Developer

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