A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Resetting MC _width ?

  1. #1
    Senior Member foochuck's Avatar
    Join Date
    Aug 2000
    Location
    Estero, FL
    Posts
    522

    Resetting MC _width ?

    I'm trying to change an MC's _width with the following code:

    Code:
    mcpreload.loadBar._width = 1;
    But I'm not having any luck. This code works on a previous line on my script:

    Code:
    mcpreload.loadBar._width = per * 2;
    Is there another way to write this code? Or to 'reset' the loadBar mc's width back to it's original width size (1).

    Thanks

    Foochuck
    Foochuck
    http://www.myspace.com/foochuck

  2. #2
    thinking is design retrotron's Avatar
    Join Date
    Apr 2003
    Location
    Utah
    Posts
    141
    Your code looks fine syntactically, so if it's not working, then something else is the culprit, probably something is preventing that code from every executing. Throw a trace statement in right after that line just to see what you get:
    code:

    trace(mcpreload.loadBar._width); // output?



    Here's a trick you may find useful: if you make loadBar the full size (i.e. what it will be when the content is loaded 100%), then you can _xscale to work with the width in percentage. So if your loadBar is a total of 250 px wide when fully loaded, this will set your loadbar to only 1 percent of that full size:
    code:

    mcpreload.loadBar._xscale = 1;


    Likewise, this will set it to 50 percent:
    code:

    mcpreload.loadBar._xscale = 50;


    Since you work with percentage, you can change the size of your loadbar and the code will always work just right, no matter what the size. It's also nice if you get the percentage of bytes loaded and save percentage in a variable because you can always set the loadBar's _xscale to that percentage and it will make the loadBar only that big:
    code:

    // pseudocode
    mcpreload.onEnterFrame = function() {
    var percentLoaded = (target.getBytesLoaded()/target.getBytesTotal()) * 100;
    this.loadBar._xscale = percentLoaded;
    }


    absconditus.com // experiments in actionscripted design

    "I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass

  3. #3
    Senior Member foochuck's Avatar
    Join Date
    Aug 2000
    Location
    Estero, FL
    Posts
    522

    more code...

    Thanks retrotron...

    Here's more of my (frame) code - maybe this will help:

    Code:
    stop();
    
    mcpreload._visible = false;
    // flag is a file loading.
    fileLoading = false;
    
    function loadAudioFile(theURL) {
    	loadMovie(theURL, "mcholder1");
    	if (!fileLoading) {
    		fileLoading = true;
    		mcpreload._visible = true;
    		loaderInterval = setInterval(loadChecker, 50);
    	}
    }
    function loadChecker() {
    	loading = mcholder1.getBytesLoaded();
            total = mcholder1.getBytesTotal();
            percent -= (percent-((loading/total)*100))*.25;
            per = int(percent);
            mcpreload.loadBar._width = per * 2;
    		if (percent > 99) {
    			mcpreload.loadBar._width = 1;
    			mcpreload._visible = false;
    			mcholder1.gotoAndStop("loaded");
    			fileLoading = false;
    			clearInterval(loaderInterval);
    		}
    	}
    	
    btn1.onRelease = function() {
    	loadAudioFile("../flash/clip1.swf");
    };
    
    btn2.onRelease = function() {
    	loadAudioFile("../flash/clip2.swf");
    };
    Basically what's goin on here is that I load an external movie and a preloader plays, the preloader's width gets set to 200. When I try to load another movie after that, the preloader's width goes from 200 back to 1 and then loads, whereas I'd like to have it just start back at 1. Is there a way to reset a movie clip? I tried setting loadBar's width back to one (traced it also and it was reading as 1) but it doesn't seem to work. See the loadbar comes back up as being filled (aka 100 percent downloaded) and then shoots to like 1 percent and counts back to 100 percent. Any ideas?

    Thanks,

    Late Night Foochuck
    Foochuck
    http://www.myspace.com/foochuck

  4. #4
    Senior Member foochuck's Avatar
    Join Date
    Aug 2000
    Location
    Estero, FL
    Posts
    522

    Code Update

    I've updated my code..as you'll see below, I now load the preloader into a level...I reset the preloader variables to 0 each time the function to load it is called..is there an easier way to do this? If anyone knows, please advise, thanks!

    Code:
    stop();
    
    // flag is a file loading.
    fileLoading = false;
    
    function loadAudioFile(theURL) {
    	loadMovie(theURL, "mcholder1");
    	loadMovieNum("../flash/preloader.swf", 1);
    	loading = 0;
        total = 0;
        percent = 0;
        per = 0;
    	if (!fileLoading) {
    		fileLoading = true;
    		loaderInterval = setInterval(loadChecker, 50);
    	}
    }
    function loadChecker() {
    	    loading = mcholder1.getBytesLoaded();
            total = mcholder1.getBytesTotal();
            percent -= (percent-((loading/total)*100))*.25;
            per = int(percent);
            _level1.loadBar._width = per * 2;
    		if (percent > 99) {
    			unloadMovieNum (1);
    			mcholder1.gotoAndStop("loaded");
    			fileLoading = false;
    			clearInterval(loaderInterval);
    		}
    	}
    	
    btn1.onRelease = function() {
    	loadAudioFile("../flash/clip1.swf");
    };
    
    btn2.onRelease = function() {
    	loadAudioFile("../flash/clip2.swf");
    };
    Foochuck
    Foochuck
    http://www.myspace.com/foochuck

  5. #5
    thinking is design retrotron's Avatar
    Join Date
    Apr 2003
    Location
    Utah
    Posts
    141
    I'm not sure I totally understand ... I think I get what you want, so what exactly is it not doing right?

    absconditus.com // experiments in actionscripted design

    "I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass

  6. #6
    Senior Member foochuck's Avatar
    Join Date
    Aug 2000
    Location
    Estero, FL
    Posts
    522

    local variables

    retrotron,

    what I'm trying to do is make the variables inside the 'loadChecker' function local variables so that after the function runs they 'die' and then when I run it again they will be reset...here's what I've done inside the loadChecker function:

    Code:
        var loading = mcholder1.getBytesLoaded();
        var total = mcholder1.getBytesTotal();
        var percent -= (percent-((loading/total)*100))*.25;
        var per = int(percent);
    I get an error when I try this saying that a ';' is expected in the 'var percent -= (percent-((loading/total)*100))*.25;' line.

    Any suggestions? Will what I'm trying to do work? What am I doing wrong?

    Thanks

    Foochuck
    Foochuck
    http://www.myspace.com/foochuck

  7. #7
    thinking is design retrotron's Avatar
    Join Date
    Apr 2003
    Location
    Utah
    Posts
    141
    Ah, I see. Cool, good plan.

    I was actually wondering about that percent line, thinking that it might throw an error. Try this:
    code:

    var percent = (percent-((loading/total)*100))*.25;


    I removed the minus sign because doing something like
    code:

    percent -= 5;


    is a shorthand for this:
    code:

    percent = percent - 5;


    So by having the -= in that line and then also having percent - .... was redundant. Anyways, let me know if removing that minus sign works or not. The rest of your code looks good, which is why I'm confused.

    absconditus.com // experiments in actionscripted design

    "I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass

  8. #8
    Senior Member foochuck's Avatar
    Join Date
    Aug 2000
    Location
    Estero, FL
    Posts
    522
    Retrotron,

    I've tried changing the -= operator to a = operator, but it causes the preloader bar script I use not to work. Is there any other way to turn that variable into a local variable?

    Thanks

    -Foochuck
    Foochuck
    http://www.myspace.com/foochuck

  9. #9
    thinking is design retrotron's Avatar
    Join Date
    Apr 2003
    Location
    Utah
    Posts
    141
    Could you post the .fla?

    absconditus.com // experiments in actionscripted design

    "I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass

  10. #10
    Senior Member foochuck's Avatar
    Join Date
    Aug 2000
    Location
    Estero, FL
    Posts
    522

    source file is too big, but...

    retrotron,

    my source fla is too big to post, but here's my actionscript from frame 1 of the _root movie:

    Code:
    stop();
    
    // flag is a file loading.
    fileLoading = false;
    
    function loadAudioFile(theURL) {
    	loadMovie(theURL, "mcholder1");
    	loadMovieNum("../flash/preloader.swf", 1);
    	loading = 0;
        total = 0;
        percent = 0;
        per = 0;
    	if (!fileLoading) {
    		fileLoading = true;
    		loaderInterval = setInterval(loadChecker, 50);
    	}
    }
    function loadChecker() {
    	    loading = mcholder1.getBytesLoaded();
            total = mcholder1.getBytesTotal();
            percent -= (percent-((loading/total)*100))*.25;
            per = int(percent);
            _level1.loadBar._width = per * 2;
    		if (percent > 99) {
    			unloadMovieNum (1);
    			mcholder1.gotoAndStop("loaded");
    			fileLoading = false;
    			clearInterval(loaderInterval);
    		}
    	}
    
    for (i=1; i <= 6; i++) {
    _root["btn"+i].index = i;
    _root["btn"+i].onRelease = function() {
    loadAudioFile("../flash/clip" + this.index + ".swf");
    };
    }
    Is there anything else I could explain to you that would help?

    -Foochuck
    Foochuck
    http://www.myspace.com/foochuck

  11. #11
    thinking is design retrotron's Avatar
    Join Date
    Apr 2003
    Location
    Utah
    Posts
    141
    Well, try this and tell me what the output is:
    code:

    stop();

    // flag is a file loading.
    fileLoading = false;

    function loadAudioFile(theURL) {
    trace("theURL: " + theURL);
    loadMovie(theURL, "mcholder1");
    loadMovieNum("../flash/preloader.swf", 1);
    loading = 0;
    total = 0;
    percent = 0;
    per = 0;
    count = 0;
    if (!fileLoading) {
    trace("fileLoading is false");
    fileLoading = true;
    loaderInterval = setInterval(loadChecker, 50);
    } // end if (!fileLoading)
    } // end loadAudioFile()

    function loadChecker() {
    trace("\n------------------------------------------------");
    trace("iteration: " + count + "\n");
    count += 1;
    loading = mcholder1.getBytesLoaded();
    total = mcholder1.getBytesTotal();
    trace(loading + "/" + total);
    percent = ((loading/total) * 100) * 0.25;
    trace("percent: " + percent);
    per = int(percent);
    trace("per: " + percent;
    _level1.loadBar._width = per * 2;
    trace("loadBar._width: " + _level1.loadBar._width);
    if (percent > 99) {
    unloadMovieNum (1);
    trace("preloader gone? " + _level1.loadBar);
    mcholder1.gotoAndStop("loaded");
    trace("mcholder: " + mcholder1);
    fileLoading = false;
    clearInterval(loaderInterval);
    trace("cleared: " + loaderInterval);
    } // end if (percent > 99)
    } // end loadChecker()

    for (i=1; i <= 6; i++) {
    _root["btn"+i].index = i;
    _root["btn"+i].onRelease = function() {
    loadAudioFile("../flash/clip" + this.index + ".swf");
    }; // end onRelease()
    } // end loop


    absconditus.com // experiments in actionscripted design

    "I really must get a thinner pencil. I ca'n't manage this one a bit: it writes all manner of things that I don't intend". // Alice, Through the Looking Glass

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