A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: (Flash 6, AS2) load jpg into movieclip and change size

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    6

    (Flash 6, AS2) load jpg into movieclip and change size

    ok... here's a little background, I'm working on a UI for a set top box that has a linux os, which runs a java virtual machine, which loads a flash (swf) interface!

    I’m trying to load a jpg into a MovieClip using the loadMovie() command because the MovieClipLoader object was introduced in Flash 7, which the box cannot run. I’m preloading the image using getBytesLoaded() and getBytesTotal() and after it’s loaded I want to stretch it to a certain size. I’m having 2 problems:

    1) The FIRST time I run the loadMovie command, it doesn’t always load the jpg, and getBytesTotal is set to -1. After I load it a second time, the preloader works fine.

    2) I cannot use mc_name._width = 1000 to scale the width of the jpg image to a certain width. I’ve tried my code on a fresh flash file and it works on a computer using Flash 6, Actionscript 2, but not on the box. What’s weird is that if I use mc_name._xscale instead of mc_name._width, it works.

    Here's the code:

    Code:
    ImgUrl = "http://img143.imageshack.us/img143/6639/1680x1050k.jpg";
    _root._container_mc.removeMovieClip();
    _root.createEmptyMovieClip("_container_mc",_root.getNextHighestDepth());
    _root._container_mc.createEmptyMovieClip("_holder_mc",_root._container_mc.getNextHighestDepth());
    
    var ad = _root._container_mc._holder_mc.loadMovie(ImgUrl);
    
    this._preloader = setInterval(function()
    {
    	trace("waiting to load image");
    	_pLoaded=_root._container_mc._holder_mc.getBytesLoaded();
    	_pTotal=_root._container_mc._holder_mc.getBytesTotal();
    	trace("loaded/total: " + _pLoaded + "/" + _pTotal);
    	if(_pLoaded > 0 && _pLoaded >= _pTotal){
    		trace("image loaded");
    		clearInterval(this._preloader);
    		_root._container_mc._holder_mc._height = 200;
    	}
    },
    100);
    As I said, this works perfectly on a computer, but not on this box... I was wondering if you knew another way to scale a loaded jpg.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Not sure about that type of set up (linux/java), but maybe you should not use absolute paths (ie: _root) if there is any 'loading' process (...which loads a flash (swf)...)
    Try relative paths, ie: this, _parent, etc.

    Also, note that:
    your interval never clears. Should be: clearInterval(_preloader);
    getNextHighestDepth is Flash 7

    gparis

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    6
    Quote Originally Posted by gparis View Post
    Not sure about that type of set up (linux/java), but maybe you should not use absolute paths (ie: _root) if there is any 'loading' process (...which loads a flash (swf)...)
    Try relative paths, ie: this, _parent, etc.
    I understand your point, but thats not the problem, since _root._container_mc._holder_mc._xscale = 50; works, but _root._container_mc._holder_mc._width = 50; doesn't work.

    Now I would gladly use _xscale if it worked in the same way as _width, but _xscale scales by percentage, so I can't just set the width. I've made a fairly simple calculation in order to use _xscale, but I really would prefer to use _width, as it does what it does more gracefully.

    This is my workaround:

    _root._container_mc._holder_mc._xscale = (desired_width/current_width)*100;


    Quote Originally Posted by gparis View Post
    Also, note that:
    your interval never clears. Should be: clearInterval(_preloader);
    getNextHighestDepth is Flash 7

    gparis
    Thanks for pointing out getNextHighestDepth is from Flash 7... didn't notice. It wasn't causing any (noticeable) problems.

    Btw, my interval DOES get cleared. Inside the setInterval function, there's an if statement that detects if the image is fully loaded. It clears the interval after the image is loaded. If you noticed that and you're suggesting that my code is incorrect, you're right and I fixed it before posting the code but forgot to make the change to this post.

  4. #4
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    dont know about the box - but you cannot set the _width of an empty movieClip but you can set the _xscale of an empty movieClip. this suggests that your code is not waiting for the image to fully load before you are trying to adjust its size. maybe.

  5. #5
    Junior Member
    Join Date
    Aug 2009
    Posts
    6
    hmmm... that's interesting actually.

    Well look at my code... is it not fully loading the jpg?? Can you suggest an alternate way to load the jpg?

  6. #6
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    try making it wait a few seconds beyond the load complete time just to test it out.

  7. #7
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    If you correct the path, as i suggested, it works well.

    gparis

  8. #8
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    i have a function that i used in Flash 6 to load, position and size a jpg.
    It works by looping the _width property to detect that the image has
    loaded and instanciated the movieclip ( an empty clips width = 0 )

    Hope it helps
    PHP Code:
    depth 1;

    function 
    loadFile(ref,dep,file,xp,yp,w2,h2){
    ref this.createEmptyMovieClip(ref,dep);
    ref2 ref.createEmptyMovieClip('inner',0);
    ref2.loadMovie(file);

    ref.onEnterFrame = function(){
    if(
    ref2._width 1){
    ref._x xp;  
    ref._y yp;
    ref._width w2;
    ref._height h2;

    ref.onRelease = function(){
    trace(this+" "+this._width+"x"+this._height);
    };

    delete ref.onEnterFrame;
    }     
    };
    };

    loadFile("pic1",depth++,"http://img143.imageshack.us/img143/6639/1680x1050k.jpg",10,10,100,200); 

  9. #9
    Junior Member
    Join Date
    Aug 2009
    Posts
    6
    Quote Originally Posted by gorlummeeguvnor View Post
    try making it wait a few seconds beyond the load complete time just to test it out.
    That didn't work.

    Quote Originally Posted by gparis View Post
    If you correct the path, as i suggested, it works well.

    gparis
    ok as I said before, if the _xscale can use _root to reference the object and scale the mc properly, then _width should do the same thing. For the sake of being thorough, I tried using parent and it didn't work -- I mean the _width command still didn't work.


    Quote Originally Posted by a_modified_dog View Post
    i have a function that i used in Flash 6 to load, position and size a jpg.
    It works by looping the _width property to detect that the image has
    loaded and instanciated the movieclip ( an empty clips width = 0 )

    Hope it helps
    That's a smart idea. Unfortunately I just tried it and still doesn't work.

    Starting to think it's an issue with the box... not that I'm surprised.

    If anyone else has any other suggestions, please suggest. To everyone who has helped until now... Thanks!

  10. #10
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    When i said it works, i meant the _width & _height work well. At least when i try it on my HD. Now when you say a_modified_dog's doesn't work either, I'd see 2 options:
    There is something in the set up that prevents the loop to work, for example there IS a swf, or else, that loads your flash, preventing all absolute paths (my 1st post) to work. The fact that amd's doesn't work either (and all his paths are relative) just closed that theory.
    The other thing i see is that there is a problem with the Flash plugin.
    Try your 'loop' with 2 frames (the old way) instead of an enterFrame or an interval.

    gparis

  11. #11
    Junior Member
    Join Date
    Aug 2009
    Posts
    6
    gparis, you keep going back to the path, even though I told you right from the beginning that _xscale worked using the _root path, while _width did not in the same situation.

    Regarding the interval... it definitely is looping as I have traced the loop to make sure it's running. It definitely loads the image BEFORE attempting to use the _width command.

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    are you having any luck ?
    is the issue still the box ?
    i have uploaded a AS1 file for testing.
    does it work on your box ?

    http://www.jackleaman.co.uk/test/loa..._jpg_size.html

  13. #13
    Junior Member
    Join Date
    Nov 2009
    Posts
    7
    this script is not working on opera and firefox for strange and unknown reasons i tried many times

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