A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Containers in Flash?

  1. #1
    Senior Member
    Join Date
    Oct 2004
    Location
    Rio de Janeiro, Brazil
    Posts
    344

    Containers in Flash?

    I was thinking if there is a way to put a "container" in a MC timeline. My idea would be to have these "containers" where I could instantiate pictures, in accord of my needings.

    For instances, suppose that you have 10 photographies and would like to randomize this photographies, in order to show an animation with one of them, each time.

    Then, the animation would be done with the "containers" and not with the photos, and the photos would be instantiated inside the "containers".

    This is possible in Flash?

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Yes it's possible. There are a few ways to do it.

    The loadMovie() function can be used to load images or movies into container movieclips. In this case, the images or SWFs would be served up separately from your web server.

    If you want to keep all the pictures in your library, you can export them, and then use attachMovie() to dynamically instantiate them from variable names, which change each time you run animations.

  3. #3
    Senior Member
    Join Date
    Oct 2004
    Location
    Rio de Janeiro, Brazil
    Posts
    344
    What's the trick to create a container MC?
    I am trying, but think that I dont know exactly what to do...

    I created an empty MC and called it "empty". Then I hard-instantiated (clicked and dragged from library to the stage) it in my main timeline as "empty1", and made a simple motion tween. Of course, when I run that, nothing appears, because the hard-instantiated MC has nothing.

    Then I created another MC with just one frame with a photography, called "pic".

    Now, my idea is from within code (with actionscript) to instantiate the "pic" MC as "pic1" into "empty1", in the very first frame of the main timeline. Well, the problem is that I cant see HOW can I instantiate a MC inside another!!!

    Can you help me????

    Thanks!

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    _root.createEmptyMovieClip()

    can be used to create movieclips. Most folks tend to use it TWICE when using it in conjunction with loadMovie().

    Like so:

    code:

    _root.createEmptyMovieClip('mc1', 1);
    mc1.createEmptyMovieClip('mc2', 1);
    mc1._x = 100;
    mc1._y = 150;
    // etc...
    mc1.mc2.loadMovie("mypicture.jpg");



    The reason for creating two nested movieclips is that the loadMovie() call completely wipes out all the properties (of mc2, in this case), so this allows you to place the loaded movieclip at a particular location, becaue mc1._x & _y won't get wiped out.

    If you're using attachMovie(), you dont' need to use createEmptyMovieClip - just attach the movie and put it where you want.

    _root.attachMovie("mypicture", "mc1", 1);
    mc1._x = 100;
    mc1._y = 150;

    However, in this case, "mypicture" needs to be in the library and exported.

  5. #5
    Senior Member
    Join Date
    Oct 2004
    Location
    Rio de Janeiro, Brazil
    Posts
    344
    Hi! Thanks for the help!
    I think that I am almost there, but nothing yet!!!

    I am trying to use attachMovie (I use Flash 5).
    The situation is that I want to have a MC with an animation (just like something sliding from left to right). But this "something" will be changed from times to times.

    Well, I made this animation with a "nothing" sliding from left to right. This "nothing" is a MC with just one blank frame. Then I am trying to instantiate another MC inside that.

    I put in the first frame of the main timeline the following code:

    empty1.attachMovie ("pic","pic1",1);
    empty1.pic1._x = 100;
    empty1.pic1._y = 100;

    PS: pic is exported through "linkage" option.

    Nothing happens!!!

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