A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Using loadMovie to import external jpg's

  1. #1
    Junior Member
    Join Date
    Apr 2002
    Posts
    5
    I want to make a gallery with both a flash page and a html page (for people without flash-plugin). Therefore I want to import external jpg-files instead of having them as a part of my swf-file. According to the flash mx tutorial ("Loading an image or sound dynamically"), this should be quite straight forward using the loadMovie command, but I can't get it to work.

    I have a object (animation) called "pic1". I have another object (animation) in the beginning of the film with the following action script:

    onClipEvent(load)
    {
    pic1.loadMovie("pic1.jpg", "")
    }

    Later I introduce "pic1" on the work area, but every time I've tried it's just blank. It doesn't import the jpg file.

    Any ideas?

    Cheers,
    Unity

  2. #2
    Senior Member
    Join Date
    Mar 2002
    Location
    The Netherlands
    Posts
    144
    Hi,

    perhaps you can try to load the image into an empty target movie clip. (just create an empty movie clip, and drag it on the stage)

    then use this code:
    loadMovie("image.jpg", target );

    Where target is the name of your target movie clip.
    It works for me......this also has the advantage of changing properties of your target...you can resize it etc.

    Try it!!

  3. #3
    Member
    Join Date
    Oct 2000
    Posts
    40
    <b>Later I introduce "pic1" on the work area, but every time I've tried it's just blank. It doesn't import the jpg file.</b>

    Make sure your movie clip that houses the imported jpg is in the same frame as your actionscript is running in. (does that make sense at all?...=_=' )

    Another words, make sure ur movie clip "pic1" is already on the stage with the other movie clip that is doing the onLoad event script.

    Hope it helps.


    PS Interestingly, I have tried using empty movie clips to import jpg, but they don't work for me. I had to always a jpg placed inside of the movie clip inorder for it to work. dont' know y though..

  4. #4
    Junior Member
    Join Date
    Apr 2002
    Posts
    5

    Wink Frustrating, look at this little sample...

    I'm still not able to load an external jpg. To try to make it as simple as possible, I've made a small test page with the following objects:

    "activator" (movie clip) (just a 30x30 white square) (instance name "activator")
    "dot.jpg" (imported graphic) (just a 5x5 white square)
    "pic1" (movie clip) (consisting of dot.jpg and 3 other white squares) (instance name "pic1")

    In addition I have the external file "001.jpg" which I want to load into pic1.

    My timelines look like this:
    Layer1: "activator" x 5 frames
    Layer2: "pic1" x 5 frames

    "activator" has the following action attached to it:

    onClipEvent(load)
    {
    loadMovie("001.jpg", pic1);
    }


    The only thing that happens when I play this movie, is that "activator" disappears, nothing happens to "pic1" at all.

    If I attach the action to "pic1" instead of "activator", "pic1" disappears. But why isn't the jpg loaded, and why is only the movieclip that the action is attached to affected and not the target clip?

    You can find the files here:
    http://jellopages.net/flashtest/loadmovie.swf
    http://jellopages.net/flashtest/loadmovie.fla
    http://jellopages.net/flashtest/001.jpg

  5. #5
    Junior Member
    Join Date
    Apr 2002
    Posts
    4
    check out load_images.fla in the samples folder of flash mx or from the macromedia site.

    It loads external jpgs into a slide viewer.

  6. #6
    Member
    Join Date
    Oct 2000
    Posts
    40
    Okay, here is your answer to your problem:

    <b>
    The only thing that happens when I play this movie, is that "activator" disappears, nothing happens to "pic1" at all.</b>

    I have noticed whenever there is an error in actionscript in MX, the movie clip that hosts the scripts would disappear. If it is the main time line, it would keep looping itself even if you have a STOP (); at the end. Weird, but effective.

    <b>
    "activator" has the following action attached to it:

    onClipEvent(load) {
    loadMovie("001.jpg", pic1);
    }
    </b>

    Your target is wrong. Because Pic1 is an movie clip instance in the maintimeline, and has no relationship with the activator movie clip. Therefore, you have to make reference by using: _root.pic1

    So I guess it will look like this...

    onClipEvent (load) {
    loadMovie("001.jpg", _root.pic1);
    }

    Hope this helps.

    Cheers.

  7. #7
    Junior Member
    Join Date
    Apr 2002
    Posts
    5
    Okidoki!

    Here's the solution! Thanx to kidwhiz for telling me about the sample file that comes with FlashMX. I found the answer there.

    Problem 1: I was using Opera web browser, and for some reason it doesn't understand the loadMovie command when I'm testing the page on my computer. Opera doesn't understand the sample file that comes with Flash either, so it isn't just me... I was so annoyed when I discovered this, since I had been testing my page in Opera all the time. Opera can read my page perfectly when I upload it and look at it on-line, though.

    Problem 2: You can't just use "onClipEvent()" or similar to trigger the loadMovie command. You have to use an "if..." statement. At least that's the only solution I found.

    Here's the script and links to the files.

    Objects:
    "pic1" (movie clip, white square 200x200) (instance name "pic1")

    External files:
    "001.jpg" (144x180)

    My timelines look like this (if you don't understand it, download my source file and have a look):

    Layer1, frame 1: Empty, but with the following code:
    a = 1
    if (a == 1)
    {
    loadMovie("001.jpg", pic1);
    a++
    }

    Layer1, frame 2: Empty, but with the following code:
    stop();

    Layer2, frame 1 and 2: "pic1"


    You can find the files here:
    http://jellopages.net/flashtest/loadmovie.html
    http://jellopages.net/flashtest/loadmovie.fla
    http://jellopages.net/flashtest/001.jpg


    Thankyouthankyou everyone who replied to my post!

    - Unity

  8. #8
    Junior Member
    Join Date
    Apr 2002
    Posts
    5
    Oops, sorry, I was wrong regarding "onClipEvent()". You can use that as well. I put another instance of "pic1" on the timeline (with another instance name, obviously) and attached the following code to it:

    onClipEvent(load)
    {
    loadMovie("001.jpg", _root.pic1);
    }

    So that works just as well. But with the script in my earlier post you don't need the extra movieclip, you can just attach it to an empty frame.

    - Unity

  9. #9
    Junior Member
    Join Date
    Apr 2002
    Posts
    2
    Make sure that the JPEG you want to load is not progressive.If it is all the lovely code in the world won't help.

    Cheers

  10. #10
    Junior Member
    Join Date
    Jan 2001
    Posts
    16
    why wont progressive jpegs work? that really sucks...my site has over 2,000 progressive jpegs I had planned on loading into a flash interface >_<

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