flash actionscript:
Hey guys, Im working on a flash project that dynamically loads other flash videos into a 'holder' movie clip. This holder should never be larger than 500x330 however, some of the files it loads may be larger than that. At any time, there maybe 1-N files because Im using XML to store the filenames (and display names) so when I click on a button (1,2,3,4 and 5 and "pagination" is used) I clear the previous movieclip (or so I think), load the current file into the holder_mc and then calculate offsets for centering the holder_mc (the holder_mc is actually a child of 'main_mc') I also try and scale the holder_mc down to fit the required dimensions of 500x330.... This is where it goes wacky. First off all, I have to click the button 3 times (reload the same swf 3 time) before it will scale and position correctly. Im 100% positive that the previous movie is being cleared and if it isn't then theres a problem with flash it self because i have followed the documentation and about 10 articles just to ensure that I was doing it right) Anyway, the problem is... sometimes they are PERFECT and other times they are to large, to small, etc. Im going nuts trying to solve this. I was actually having the same issue with another project where once I tried to "restart" the game (ie. resetting everything back to original values) the collision detection was totally messed up... it almost seemed as though the previous data was causing collisions even when the actual movie clip (and I put a box for the bounds for visuals) was tripping a collision WAY TO EARLY). Anyway, I really need help with the previous issue. Please help!! -Jason
if you're using loadMovie or loadMovieNum are you using a preloader (and if you're using the moviecliploader class are you using the onLoadInit method of its listener) to determine when loading is complete and then assigning your movieclip properties?
I played around with the moviecliploader the other day but I don't really know what the benefits are over the standard loadMovie. Heres the basic function (was much more complex than it is now) function LoadMc() { var file = mcList[curPage*5+index]; main_mc.holder_mc.clear(); loadMovie(file, main_mc.holder_mc); //this gets called in onEnterFrame so only allow this function to be ran once //per 'click' loaded = true; if(main_mc.holder_mc._width > 500 or main_mc.holder_mc._height > 330){ main_mc.holder_mc._width = 500; main_mc.holder_mc._height = 330; } var xcenter = ((500 - main_mc.holder_mc._width)*0.5); var ycenter = ((330 - main_mc.holder_mc._height)*0.5); main_mc.holder_mc._x = xcenter; main_mc.holder_mc._y = ycenter; }
MovieClipLoader allows you to control when the events are fired for your resizing. It allows you to add listeners for handling progress and load complete. This insures that all of the MovieClips properties are available to you. What you are probably seeing is a result of your files not being completely loaded (flash environment may result in 70%+ of the time it will work) which can be hard to test in the flash environment unless you test bandwidth etc. I'd rework your code to use the MovieClipLoader class and event listeners.
the _width and _height properties of your target movieclip aren't available until loading is complete. ie, you must use preloader code to ensure loading is complete so you can accurately access the target's _width and _height. and the benefit of the moviecliploader class is you don't need to use preloader code. you use the onLoadInit() method of your moviecliploader's listener.
Sweet! ok, so i've got the moviecliploader working along with a listener and I seem to be successfully getting the data that I need. However, I still notice a bug... in the width/height test, I was simply resetting the mc's width and height to that of the required dimensions, however, if I load a movie that is MUCH larger that the size, every other movie clip there after seems to be scaled much to small.... blah!
Ok, here it is: _root.onEnterFrame = function() { handleRollOver(b1_mc); handleRollOver(b2_mc); handleRollOver(b3_mc); handleRollOver(b4_mc); handleRollOver(b5_mc); if (names[curPage*5+0] == undefined) { b1_mc._visible = false; } else { b1_mc._visible = true; } if (names[curPage*5+1] == undefined) { b2_mc._visible = false; } else { b2_mc._visible = true; } if (names[curPage*5+2] == undefined) { b3_mc._visible = false; } else { b3_mc._visible = true; } if (names[curPage*5+3] == undefined) { b4_mc._visible = false; } else { b4_mc._visible = true; } if (names[curPage*5+4] == undefined) { b5_mc._visible = false; } else { b5_mc._visible = true; } if (loading == true) { main_mc.holder_mc._visible = false; loading_mc._visible = true; if (loadingscreendone == false) { if (loading_mc._currentframe == loading_mc._totalframes-1) { loadingscreendone = true; loading = false; main_mc.holder_mc._visible = true; } } } else { loading_mc._visible = false; } b1_mc.str.htmlText = names[curPage*5+0]; b2_mc.str.htmlText = names[curPage*5+1]; b3_mc.str.htmlText = names[curPage*5+2]; b4_mc.str.htmlText = names[curPage*5+3]; b5_mc.str.htmlText = names[curPage*5+4]; }; var myLoader:MovieClipLoader = new MovieClipLoader(); var myListener:Object = new Object(); myListener.onLoadComplete = function(target:MovieClip,httpStatus) { trace("Loaded"); } myListener.onLoadInit = function(target:MovieClip) { trace("INIT WIDTH: " + target._width); if(target._width > 500 || target._height > 330) { } var xcenter = ((500 - target._width)*0.5); var ycenter = ((330 - target._height)*0.5); target._x = xcenter; target._y = ycenter; } myLoader.addListener(myListener); function LoadLos() { var file = loList[curPage*5+index]; myLoader.unloadClip(main_mc.holder_mc); main_mc.holder_mc.clear(); myLoader.loadClip(file,main_mc.holder_mc); }
I only have 7 posts here but I am not a flash n00b so please don't think Im just a kid trying to get his homework done for him. I have been developing in flash for a little over a year and a half and have been programming for about 5 ;) My code looks hacked right now because, well right now it is until I can figure out this issue.
um... no not at all... the only problem is that the movie clips seems to be affected by the previous movie clip. I was saying that earlier because most people assume you know nothing when your new to a forum. Anyway, my partner has been developing in flash since 4 or 5 and even he can't figure out the problem.
ohh and the if statement should only have: main_mc.holder_mc._width = 500; main_mc.holder_mc._height = 330; I took that out for the time being to see if it was effecting movie clips that did not meet the if requirements.
are you saying, if you load 2 files with your mcl that the positioning of the 2nd is affected by the position of the 1st? if so, what's main_mc.holder_mc.clear() doing? and is there any other code affecting the positioning of your target movieclip?
no, not at all. The previously loaded movie clip seems to have been effecting the new one even after it was cleared. However, I solved the problem now by simply reseting the holder_mc's properties in the onLoadStart and I was able to scale the movieclips down pretty nicely by subtracting the difference in size from the width and height of the movieclip... var xdif = Math.abs(500 - target._width); var ydif = Math.abs(330 - target._height); if( target._width > 500 or target._height > 330) { target._width = target._width-xdif; target._height = target._height-ydif; } and then the centering of the movie clip works about the same way. Thanks for the help. If it wasn't for the movieClipLoader I would be totally stuck.
Don't see what you're looking for? Try a search.
|