Display object fixed size or how to make “overflow:hidden” in Flash
October 20th, 2009
I don’t like some things in the Flash. For example it scaling system of parent/child objects.
So there is new issue i met yesterday: i was loading external SWF to my AS3 application, so it size was specified 400×300 pixels for example, but when it loaded – some stuff inside this SWF make it 3000px height and ofcourse that force my movieclip which contain this SWF to change it height on 3000px too. You should to know that if external SWF is AS1 or AS2 application then AS3 use AVM1Movie class to proccess this Flash-application, this mean that you can not manage elements inside this SWF.
The main thing i need is to prevent resizing of my container movieclip. So i was wishing for such property like overflow with value hidden line in CSS. I tried to use mask for my movieclip or my AVM1Movie instance, but what mask is doing it just hide stuff outside mask, but size remain the same, so it wont help you. Truly i’v started thinking that there is no solution, but i knew solution must be very easy for this. And really! There is very easy solution, is to use scrollRect for clipping display object
So code for my problem looks like:
// Loader class to load externall stuff var my_loader:Loader = new Loader(); // there we are saying to start loading from specified url my_loader.load(new URLRequest(my_url_string)); // adding our loader to movieclip, Loader derived from DisplayObjectContainer, so we can make almost the same things as with Sprite, but Loader for example does not implement methods to manipulate childs my_movielcip.addChild(my_loader); // here is we'r catching event when clip is loaded my_loader.contentLoaderInfo.addEventListener ( Event.COMPLETE, clipLoaded); function clipLoaded(ev:Event):void{ // our secret weapon line, force our newly loaded content to have init size. If it's has any stuff longer that width or height, Rectangle crop it using scrollRect property LoaderInfo(ev.target).content.scrollRect = new Rectangle(0, 0, ev.target.width, ev.target.height); }
I know this is very simple solution. But if you don’t aware of this it can take a while to find out this. I hope it will be usefull for you in the future.



