A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: attachMovie (nor working) after loadMovie

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    4

    attachMovie (nor working) after loadMovie

    Hi.
    I have a problem:
    I have some presentation and i need to place there a watermark (default and from a file)
    I have this code:

    _root.wm.attachMovie("zastepczy", "zastepczy1", 1);

    myVars = new LoadVars();
    myVars.onLoad = function(success){
    if(success){
    wm.loadMovie("watermark.png", 1);

    }else{
    }
    delete myVars;
    }
    myVars.load("watermark.png", 1);


    if (_root.wm._width < 50 || _root.wm._height < 15) {
    _root.wm.attachMovie("zastepczy", "zastepczy2", 1);
    }



    Everything is fine except last 'if' (if width of wm < 50 or height of wm < 15).
    After loadMovie function attachMovie just doesn't work

    I've tried without 'if' function (just _root.wm.attachMovie("zastepczy", "zastepczy2", 1) but it doesn't work either).

    Please, help

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hi,

    and wow, that is a really messed up code :P

    LoadVars is only used to send and retrieve variables, and also to retrieve the contents of a file. In this case, you won't be loading watermark.jpg, but rather just its content in text format, but Flash is not capable to get the RAW data of an image file. It will return nothing, and what you're doing is that after it loads the image file as nothing (no text) into Flash, you're then loading the actual image into a movieclip into Flash, and that code is executed once the image's RAW data (no text) has been loaded into Flash, while your if statement is static, meaning that it is only executed ONCE and that is when you enter the Frame that code is on. So, when you enter that frame, LoadVars is created and then the if statement is checked, but after a few milliseconds, then the actual image is loaded (because onLoad takes a bit time to load the data into Flash), but the if statement has long since been executed once, so it won't be checking again, because there's no code around it that tells it to continuously check whether wm's width and height are greater than certain numbers. What you can do, is to simply wrap the if statement with an onEnterFrame loop, which keeps executing the code (keeps checking), but this is not adviced to do, but here's the code (for if statement):

    Actionscript Code:
    onEnterFrame = function(){
        if (_root.wm._width < 50 || _root.wm._height < 15) {
            _root.wm.attachMovie("zastepczy", "zastepczy2", 1);
            delete onEnterFrame;
        }
    }

    but what you can do, which is also MUCH better, is to use the MovieClipLoader class, which ships with an event handler for when the image has been loaded into Flash, and THEN you can run the if statement once, or, if you only want to check when the image has loaded, you don't even need to do that:

    Actionscript Code:
    mcLoader = new MovieClipLoader();
    mcLoader.loadClip("watermark.png", wm);

    loader = new Object();
    loader.onLoadInit = function(){
        // codes here will be executed once the image has been loaded into Flash
        _root.wm.attachMovie("zastepczy", "zastepczy2", 1);
    }
    mcLoader.addListener(loader);
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    4
    it's not working.
    what it meant to be:

    defaultly load zastepczy movieclip (with 'zastepczy' linkage) into wm

    if there is watermark.png then load it, else stay with 'zastepczy' mc.

    when (after loading watermark.png) wm is h < 15 or w < 50 (because watermark.png is to small) load 'zastepczy' mc.

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I don't seem to understand what you mean :S?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I think its put this next to when the .png is loaded into the movieclip

    Actionscript Code:
    mcLoader = new MovieClipLoader();
    mcLoader.loadClip("watermark.png", wm);

    loader = new Object();
    loader.onLoadInit = function(){
        // codes here will be executed once the image has been loaded into Flash
    [B]ImageIsLoaded=true;[/B]
        _root.wm.attachMovie("zastepczy", "zastepczy2", 1);
    }
    mcLoader.addListener(loader);

    Then in an onEnterframe:

    Actionscript Code:
    onEnterframe=function(){

    if(ImageLoaded==true){
    //do nothing
    }
    else {
    load the .png
    }
    };

    Hope this helps , and that I really understood what's going on with your situation.

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