rulururu

post Display object fixed size or how to make “overflow:hidden” in Flash

October 20th, 2009

Filed under: Flash/Flex — Alex Bylim @ 3:04 pm

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.

post Finding text which is not html tag via regular expressions

October 10th, 2009

Filed under: RegExp — Alex Bylim @ 1:10 am

Hi, guys. Today i’v encountered with some insteresnting task. I have html text, for example:

<strong>"Skwak"</strong><p> is an awesome French.<p>

So I wanna to fetch text that which is not html tag, some kind of html tag stripping. Yes, you easily can find all tags and remove them, you can find how to do this in google, there are a lot of links and descriptions. Regular expression for this is pretty simple and looks like this:

<[^>]*>

But what if you want to get “Skwak” or is an awesome French, the regular expression for this will be complex enough. I knew that to implement this i need to use lookahead and lookbehind assertions but could not find quick answer in the internet, so it took me a while to solve this problem, and now I wanna share my solution with you. Here is:

(?:(?!>).(?!([^<]+)?>))

post Focus on stage element via JSFL

October 8th, 2009

Filed under: JSFL — Alex Bylim @ 7:15 pm

Just imagine you are creating some custom panel for Adobe Flash CSx, and you want to find some element on stage or in some symbol. Ok, you can easily find it through JSFL DOM, but what’s next ? You’d probably want to make it selected, ok, code below will select element by instance name:

// getting all elements on the stage
var myElements = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements;
// looping through all elements
for (var i=0; i &lt; myElements.length; i++)
// check if element's name is what we want
  if( myElements[i].name == "element_name"){
    // clear selection
    fl.getDocumentDOM().selectNone();
    // make element selected
    myElements[i].selected = true;
    // as we found our element then quit the loop
    break;
}

Good, now our element is selected. But how can we make it be visible to user and in the center of our stage ? To achiev this we need to use zoomFactor:

Code below will force Adobe Flash IDE to show selected element in the center of  the stage window:

  fl.getDocumentDOM().zoomFactor +=  1;
  // leave zoomFactor unchanged
  fl.getDocumentDOM().zoomFactor -=  1;

For more detail info about JSFL API you can visit this link: http://help.adobe.com/en_US/Flash/10.0_ExtendingFlash/index.html

ruldrurd
Powered by WordPress, Web Design by Laurentiu Piron
Entries (RSS) and Comments (RSS)