A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: external images load - must be a syntax error on my part

  1. #1
    Junior Member
    Join Date
    Mar 2000
    Posts
    6

    external images load - must be a syntax error on my part

    I cannot seem to find what is not working here (too much holiday food, for sure).

    I am trying to load external jpegs listed in an array in an .as file (loaded at level0).

    The first case below works fine.

    code:

    loadMovie(_level0.image105[1], "jpegtar");



    I want to separate the projects so I can use the same code for all projects and just have the number separate. I am doing something wrong here but am not sure what.

    code:

    projectNum = 105;
    loadMovie("level0."+"image"+projectNum+[1], "jpegtar");



    using trace shows I am getting the right code but it doesnt find the image...?

    any help would be fantastic. thanks,

    l

  2. #2
    Junior Member
    Join Date
    Jun 2001
    Posts
    17
    If I understand your intention right, you want to construct the name of the array containig the imagenames. For constructing object-names, the eval()-Function would be the right thing to use.

  3. #3
    Junior Member
    Join Date
    Mar 2000
    Posts
    6

    thanks!

    I will try out the eval(); and let you know.

    thanks for your help.

    l
    mobile media lounge - www.wandelbar.com

  4. #4
    Junior Member
    Join Date
    Mar 2000
    Posts
    6

    eval doesnt seem to work

    hi,

    I tried using eval() but it doesnt seem to work:

    I get the right string(using trace) but using the loadMovie(); with that string doesnt work for some strange reason:

    code:
    loadMovie(_level0.image105[1],"jpegtar");



    works fine but the following doesnt.

    code:

    pNum = 105;
    iNum = 1;
    loadMovie(_level0["image"+pNum+iNum],"jpegtar");



    cant quite figure out what I am doing wrong.

    l

  5. #5
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    code:
    pNum = 105;
    iNum = 1;
    loadMovie(_level0["image"+(parseInt(pNum+iNum))],"jpegtar");


    parseInt renders the values as integers, so they can be used to perform calcs. otherwise you're saying _level0.image1061.

  6. #6
    Junior Member
    Join Date
    Mar 2000
    Posts
    6

    not quite

    thanks for the reply, I want to call the following variable:
    _level0.image1051

    and when I do a trace it calls exactly the right var - it just shows in in the output field - cannot find file: path/_level0.image1051

    I thought eval or using [] would fix it but I cannot get it to work?

    thanks for your help.

    l

  7. #7
    Junior Member
    Join Date
    Jun 2001
    Posts
    17
    I'm still not shure if I get your intention right. But maybe it helps you to know that the following piece of code is working in my environment:

    code:

    image1051 = "http://anyURL...";
    projectNum = 105;
    pictureNum = 1;
    trace(eval("_level0.image"+projectNum+pictureNum)) ;


    Output is: 'http://anyURL...'

    Is this what you're looking for?

    Regards

  8. #8
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    loadMovie function is loadMovie("someimagefile.jpg", target_mc);
    loadMovie method is some_mc.loadMovie("someimagefile.jpg");

    i'll assume some things, but is the following basically right?
    - you loaded in a bunch of variables.
    - one of these variables was image1051, whose value is a string that correlates to an image file, as would be the case with
    code:

    var image1051 = "somepic.jpg";


    - you have already created a movieclip with the instance name of 'jpegtar' that's in the current timeline and present on the stage.

    if that's all correct, the syntax you used should be fine. to ensure results, you may want to assign the target clip(jpegtar) to a variable of the same name, using the var key word, and take it out of quotes since when you reference it in the loadmovie - you'll see what i mean in the examples, which all work - using as close as i can guess to your script
    code:
    var pNum = 105;
    var iNum = 1;
    var image1051 = "somepic.jpg";
    this.createEmptyMovieClip("jpegtar",0);
    loadMovie(_level0["image"+pNum+iNum], "mc");

    code:
    var pNum = 105;
    var iNum = 1;
    var image1051 = "somepic.jpg";
    var jpegtar = this.createEmptyMovieClip("jpegtar",0);
    loadMovie(_level0["image"+pNum+iNum], jpegtar);

    code:

    var pNum = 105;
    var iNum = 1;
    var image1051 = "somepic.jpg";
    var jpegtar = this.createEmptyMovieClip("jpegtar",0);
    jpegtar.loadMovie(_level0["image"+pNum+iNum]);


    if not post the complete code or the fla

  9. #9
    Junior Member
    Join Date
    Mar 2000
    Posts
    6

    fla file

    Hello M and H,

    thanks a million for your help, this one really has me stuck now for a while. I tried all your code, eval and the others but seem to be missing something(probably something super easy). There are just lots of images to deal with.

    Here is the swf online:
    http://www.activ8.de/JAMESFEE/website

    in work:fine arteleliu (5th one down) I have set up the code.

    Here is the fla file:
    http://www.activ8.de/JAMESFEE/websit...h/JAMESFEE.fla

    the code is in label: images105

    Here is the .as file: http://www.activ8.de/JAMESFEE/websit...esfee_links.as

    it may be that I am calling these variables from a separate mc. The idea was to reuse the images105 movie clip for each project.

    any help would be great.

    thanks,
    l
    mobile media lounge - www.wandelbar.com

  10. #10
    Junior Member
    Join Date
    Jun 2001
    Posts
    17
    Hi leanbean,

    unfortunately I cannot open your files as they seem to be MX2004. But I have discovered some strange behaviour when dealing with arrays (to remember, the code in my last post constructed a somple variable).

    Let's look at the following code (see comments for output results):
    code:

    var image105 = new Array("picture1.jpg", "picture2");
    projectNum = 105;
    pictureNum = 1;

    trace( _level0.image105[pictureNum] );
    // Output is "undefined"

    trace( image105[pictureNum] );
    // Output is "picture2" (which is the expected)

    trace( eval("_level0.image105[1]") );
    // Output ร*s "undefined"

    trace(eval("_level0.image"+projectNum+pictureNum+"[1]"));
    // Output is "undefined"


    To me it looks like Flash having a problem with constructing Names of Array-Objects. From the spot I don't know any workaround for this behaviour, but wouldn't solution 2 in the example above do the job? I use it to load a bunch of images in the following way (within a for-loop) and it works fine:
    code:

    loadMovie("http://localhost/www/"+g_imageList[i]+".jpg", "container");


    The only restriction is that the name of the array with the image-list is fixed but is this a real disadvantage? I know it's not very elegant to hardcode a number of array-names but if there are not to many...
    Another way of solving your problem might be to use 2-dimensional arrays instead of constructing different array-names for every project. Or you create a custom Java-Script-Object with appropriate methods and properties in your external AS-file to store the image-lists (probably the most elegant way).
    So far I discover again and again that AS has some restrictions compared to JavaScript. So I cannot guarantee my suggestions work. Let me know if they do your job!

    Regards!

  11. #11
    Junior Member
    Join Date
    Mar 2000
    Posts
    6

    cs array issue

    Hi H,

    thanks again for your help here, I thought I was going crazy with the "undefined" always popping up with what seemed like easy code.

    I will try your solution workaround.

    here is the code as flash mx (not mx 2004).

    http://www.activ8.de/JAMESFEE/websi...sh/JAMESFEEmx.fla

    l

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