Re: [Flashcoders] working with getPixel32 and setPixel32,
Hi, this might help: http://objectpainters.com/blog/2007/11/30/inverting-the-alpha-of-a-bitmap-image/ It does not half but invert the alpha, but the principle is the same I think. The problem lies in the premultiplication of the alpha. greetz JC On Tue, Oct 7, 2008 at 4:48 AM, Juan Pablo Califano [EMAIL PROTECTED] wrote: PD: Sorry, even though the result is the same, to make more sense the second sample should read: var hexaValue:int = 0x9100ff33; var a:int = (hexaValue 24) 0xff; var rgb:int = hexaValue 0xff; var newAlpha:int = 0xcc; copyHexaValue = newAlpha 24 | rgb; trace(uint(copyHexaValue).toString(16));// traces cc00ff33 Using rgb as the name of the var that stores the value of the RGB components, instead of arg. 2008/10/6, Juan Pablo Califano [EMAIL PROTECTED]: Hi, If I haven't misread something, this a = a 1; makes no sense. Unless you're trying to divide alpha by 2, in which case I obviously missed something. If you want to extract the 4 components, you can use something like this: var hexaValue:int = 0x9100ff33; var a:int = (hexaValue 24) 0xff; var r:int = (hexaValue 16) 0xff;; var g:int = (hexaValue 8) 0xff;; var b:int = hexaValue 0xff; var newAlpha:int = 0xcc; var copyHexaValue:int = newAlpha 24 | r 16 | g 8 | b; trace(uint(copyHexaValue).toString(16)); // traces cc00ff33 If you don't bother to get the individual RGB components, just the alpha channel, try this: var hexaValue:int = 0x9100ff33; var a:int = (hexaValue 24) 0xff; var arg:int = hexaValue 0xff; var newAlpha:int = 0xcc; copyHexaValue = newAlpha 24 | arg; trace(uint(copyHexaValue).toString(16));// traces cc00ff33 Also, I'm casting to uint just to display the value in a more meaningful/readable way in the trace, but as long as you don't perform arithmetic on those values, you don't have to (because it's parsed as a bit pattern, not as numerical value, if that makes sense...). Cheers Juan Pablo Califano 2008/10/6, sebastian [EMAIL PROTECTED]: hi Glen, Kudos for the shift 1 operation, knew that was a faster operand. However, this code is still now working, now it simply doesn't change anything... :( var val:uint = getPixel32(x,y); var a:uint = (val 24) 0xff; var rgb:uint = val 0xff; a = a 1; var newval:uint = (a 32) | rgb; setPixel32(x,y,newval); I also tried changing it to say: ... var rgb:uint = val 0x00ff; a = a 1; var newval:uint = (a 24) | rgb; ... since I thought that was an error maybe, but that also doesn't influence the alpha of the pixel... :( Out of desperation I also tried: var a:uint = val 0xff00; var rgb:uint = val 0x00f; a = a 1; var newval:uint = a | rgb; and var a:uint = val 0xff00; var rgb:uint = val 0x00f; a = a 1; var newval:uint = (a 24) | rgb; :( sniff... Setting alpha for the whole MC is not an option for what I am doing. I'm trying to create trails behind things that are moving by having a video-burn like effect; by operating on the pixel level. At the moment I am using code from 'Adventures in AS', but once i have it working I'll encapsulate it and use it in a different project. The original source is: http://flashcoding.blogspot.com/2008/03/small-starfield-with-bluring-effect.html And my current draft-code modification is: package { import flash.events.*; import flash.display.*; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Rectangle; public class Starfield { var mc:MovieClip =new MovieClip(); var screendata:BitmapData; var stars:Array=new Array(); var antal:Number=500; public function Starfield(timeline) { screendata=new BitmapData(320,240,false,0x); var screen:Bitmap=new Bitmap(screendata); mc.addChild(screen); for (var i:int=0;iantal;i++) { InitStar(i); } mc.addEventListener(Event.ENTER_FRAME,this.render); timeline.addChild(mc); } private function MoveStar(index:int) { if (stars[index][0]-160 || stars[index][0]160 || stars[index][1]-120 || stars[index][1]120) { InitStar(index); } else { stars[index][0]= stars[index][0]*stars[index][2]; stars[index][1]= stars[index][1]*stars[index][2]; } } private function InitStar(index:int) {
Re: [Flashcoders] working with getPixel32 and setPixel32,
Hi, ps if you are just wanting to half the alpha something along these lines should work as well: var newbitmap:BitmapData = new BitmapData (widht, height, true, 0x0); newbitmap.draw (oldbitmap, new Matrix(), new ColorTransform(1,1,1,0.5,0,0,0,0)); greetz JC On Mon, Oct 6, 2008 at 9:17 PM, sebastian [EMAIL PROTECTED] wrote: hi folks, can any one shed some light to me on the setpixel32 and getpixel32? I'd like to be able to affect just one of the 4 components: A R G or B independently of another. Essentially, read the current ARGB using getPixel32 and then manipulate just one part of it, in my case, halve the current A value of the ARGB and then re-assign it back to the bitmap. //1: grab the HEX value for the current coordinate: var val:uint = getPixel32(x,y); //2: manipulate the HEX value of just 1 of the 4 parts, in my case the A of the ARGB: //3: re-assign it back to the display: setPixel32(x,y,val); Thanks for your help! Sebastian. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] sizing an arbitrary loaded swf
Juan, (Yeah, it was me on Flash_Tiger... :-) ) To be fair, I'd have suggested that to Andrew a while back, except he said: Thanks Steve. I thought maybe I was onto something with the LoaderInfo classes width and height props that return the nominal w and h, but this information doesn't seem to jive with what I'm observing. So I assumed he'd already tried it. :-) But to add to the SWF header debate etc. - I believe the loaderInfo.width and .height gives you what's in the header, so I don't think there's much point in actually parsing the header, because you'll get the same info. Andrew - I suspect there's something else going on in terms of scaling or some such, because I believe that loaderInfo.width and loaderInfo.height should be giving you valid results -- it may be that for some reason you're interpreting them incorrectly. Wwrong frame of reference? Ignoring the scaling of the Loader class? Try loaderInfo.width*loader.scaleX, for example... HTH, Ian On Tue, Oct 7, 2008 at 2:33 AM, Juan Pablo Califano [EMAIL PROTECTED] wrote: PD: I think someone at Flash_Tiger just found a way simpler and more straight forward means to get the stage size: Try loaderInfo.width and loaderInfo.height. http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html Cheers Juan Pablo Califano 2008/10/5, Juan Pablo Califano [EMAIL PROTECTED]: Hi Andrew, I'm not sure were the problem could be, but checking both swf's I got 640x480 and 600x200, which seems right. If I open the swf standalone (I mean double clicking on it), the player opens it with those dimensions. Plus, I've converted the to fla just to check the dimensions and I got back the same values. What the swf header contains is the size of the stage, or, in other words, the size you set for the fla document at author time (if you're using the Flash IDE; in that case, it's the numbers you set using the size button in the properties panel). I've also checked with another player from youtube and the size of the swf is 480x387, which seems to match with the rebuilt fla and with what I see in the site. Maybe those swf's are being scaled, cropped or masked by other means ? (when embedding, for instance) It's just a thought, anyway, perhaps if you post the url of the page that contains those swfs, someone is able to figure out why there's a difference between what you see on the screen and the swf's stage size. Cheers Juan Pablo Califano 2008/10/5, Andrew Sinning [EMAIL PROTECTED]: Hi Juan Pablo, I just got back to this problem and tested your SwfHeader class. From the few tests that I've run, this returns exactly the same dimensions that the LoaderInfo class does. I'm still stuck. Here's an example of a swf on YouTube: http://www.youtube.com/v/C7PH3GVj104 The LoaderInfo/SwfHeader dimensions are 640x320, but the actual dimensions appear to be 320x180. This swf http://client.shoutlet.com/static/imageplayer/viewer.php?config=http://client.shoutlet.com/file/64/5863.xml Looks to be actually 400x200 but the LoaderInfo/SwfHeader dimensions are 600x200. Juan Pablo Califano wrote: http://pastebin.be/14115 (SwfHeader class) Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] sizing an arbitrary loaded swf
Hi Ian, Some of what I'm seeing is that quite a few of the swfs that I happen to be loading contain their own internal scaling functions. Most typically I'm seeing are swfs that automatically scale to stage.stageWidth and stage.stageHeight. This is for the most part easy to detect, but there are some timing issues -- the scaling doesn't happen right away. A different issue that I'm seeing is with the videos on YouTube. The expectation is that end users will want to appropriate YouTube videos in their own content. Here are two randomly selected addresses parsed out of the embed tags: url = 'http://www.youtube.com/v/PbeMwl_PA6Ahl=enfs=1' url = 'http://www.youtube.com/v/Jag7oTemldYhl=enfs=1' When loaded into a parent swf, these both have loaderInfo.width/height of 640x480. This differs from the width and height specified by the YouTube provided embed tags of 425x344, but that's not the problem. Here's the problem, when I load these into a parent swf, with absolutely no scaling (I've checked, scaleX and scaleY are 1.0), the visible dimension of these videos is 480x385. This size seems to have no relationship to the size of the parent stage at all, whether it is 100x100 or 1000x1000. This is the method that I am using to bring in the swf: var loader:Loader = new Loader(); var request:URLRequest = new URLRequest(url); loader.load(request); addChild(loader); Here's the function I use to determine the opaque rectangle of a loader object. function getLoaderRect(loader:Loader):Rectangle { // start with a bitmap big enough for the end loader //note: it needs to be at least as big as the stage, because some swfs will automatically size to the stage var w:Number = 2*Math.floor(Math.max(stage.stageWidth, loader.contentLoaderInfo.width)); var h:Number = 2*Math.floor(Math.max(stage.stageHeight, loader.contentLoaderInfo.height)); var widgetBmp:BitmapData = new BitmapData(w, h, true, 0x); // copy the loader into the bmp widgetBmp.draw(loader); // get the rectangle around the non-transparent pixels var rect:Rectangle = widgetBmp.getColorBoundsRect(0xFF, 0x, false); return rect; } This function is not at all fool-proof because at any given time while playing, the opaque area can change. As we all know, it's not uncommon for there to be stray bits lying off to the side of the stage. It's also typical for projects to contain only a small loading animation at the beginning. From what I can tell so far, arbitrarily loaded swfs will fall into one of three categories: 1) swfs that have their own internal scaling functions that vary depending on the size of the parent swf. 2) swfs that correctly reflect the nominal w and h of their loaderInfo object. 3) swfs like the YouTube examples that are none of the above. Ian Thomas wrote: But to add to the SWF header debate etc. - I believe the loaderInfo.width and .height gives you what's in the header, so I don't think there's much point in actually parsing the header, because you'll get the same info. Andrew - I suspect there's something else going on in terms of scaling or some such, because I believe that loaderInfo.width and loaderInfo.height should be giving you valid results -- it may be that for some reason you're interpreting them incorrectly. Wwrong frame of reference? Ignoring the scaling of the Loader class? Try loaderInfo.width*loader.scaleX, for example... ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] sizing an arbitrary loaded swf
Hi Andrew, As far as I remember, the YouTube .swf is a shell around an .flv. So the dimensions of the shell .swf may bear absolutely no resemblance at all to the size of the contained video; and off-hand, I can't think of a way to get at the contained video size. But aren't they all consistent in YouTube - I mean - does it ever vary? In other words, I think your loaderInfo.width and loaderInfo.height are correct _for the Youtube shell .swf_ - but it, in turn, contains an FLV, and you have no way to get at that scaling. I'm just guessing here. :-) But AFAIK, loaderInfo.width and .height are correctly returning the width and height encoded into the SWF header. They do give you the stage size. Ian On Tue, Oct 7, 2008 at 1:39 PM, Andrew Sinning [EMAIL PROTECTED] wrote: Hi Ian, Some of what I'm seeing is that quite a few of the swfs that I happen to be loading contain their own internal scaling functions. Most typically I'm seeing are swfs that automatically scale to stage.stageWidth and stage.stageHeight. This is for the most part easy to detect, but there are some timing issues -- the scaling doesn't happen right away. A different issue that I'm seeing is with the videos on YouTube. The expectation is that end users will want to appropriate YouTube videos in their own content. Here are two randomly selected addresses parsed out of the embed tags: url = 'http://www.youtube.com/v/PbeMwl_PA6Ahl=enfs=1' url = 'http://www.youtube.com/v/Jag7oTemldYhl=enfs=1' ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] sizing an arbitrary loaded swf
Of course, it's a swf around a flv. This makes a bit more sense now. My guess is that the size of the flv _will_ vary, after all there are lots of different video formats. The YouTube shell is going to have its own internal algorithms for computing the scaling of the flv and the placement of the nav bar. These factors will determine the resulting opaque area. I'm still a bit confused though, because I'm wondering where does the YouTube shell get its information about size of the stage within which it resides, if not from stage.stageWidth/Height. Typically a YouTube shell would get loaded into an html page and the embed tags would specify the size and scaling options for the video. The standard YouTube supplied embed tags specify a size of 425x344, but I just did a test, editing the tag for both a smaller and a larger rect: the video gets scaled accordingly. So, it looks like the YouTube shell is dynamically scaling depending on the size of the stage within which it resides. However, when I wrap it in my own shell, it always gets displayed at 480x385. Of course, my intent isn't to obsess about how YouTube videos get displayed, but rather to tackle the generalized problem: A user supplies the url (or embed code) for some arbitrary content that they want to include in their own presentation (e.g. a quiz). It's easy enough to parse out the url of the content and load it into the presentation swf. The difficult part is figuring how to size the loaded swf to fit within a predefined layout. Some swfs should be cropped/masked to their nominal size and then scaled to fit the layout. Some swfs contain internal scaling functions that will reflect the stage size of the presentation swf. Other swfs don't fit nicely into either of these categories. Ian Thomas wrote: Hi Andrew, As far as I remember, the YouTube .swf is a shell around an .flv. So the dimensions of the shell .swf may bear absolutely no resemblance at all to the size of the contained video; and off-hand, I can't think of a way to get at the contained video size. But aren't they all consistent in YouTube - I mean - does it ever vary? In other words, I think your loaderInfo.width and loaderInfo.height are correct _for the Youtube shell .swf_ - but it, in turn, contains an FLV, and you have no way to get at that scaling. I'm just guessing here. :-) But AFAIK, loaderInfo.width and .height are correctly returning the width and height encoded into the SWF header. They do give you the stage size. Ian On Tue, Oct 7, 2008 at 1:39 PM, Andrew Sinning [EMAIL PROTECTED] wrote: Hi Ian, Some of what I'm seeing is that quite a few of the swfs that I happen to be loading contain their own internal scaling functions. Most typically I'm seeing are swfs that automatically scale to stage.stageWidth and stage.stageHeight. This is for the most part easy to detect, but there are some timing issues -- the scaling doesn't happen right away. A different issue that I'm seeing is with the videos on YouTube. The expectation is that end users will want to appropriate YouTube videos in their own content. Here are two randomly selected addresses parsed out of the embed tags: url = 'http://www.youtube.com/v/PbeMwl_PA6Ahl=enfs=1' url = 'http://www.youtube.com/v/Jag7oTemldYhl=enfs=1' ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS2 Memory / CPU usage
Hi Glen, maybe its not a memory issue at all and its a graphics card issue. I used to have the problem sometimes when i was animating threw the timeline. And by monitoring (self monitoring, i don't have in mind any tool that does this job) the application in flash on one side and the whole system (Windows) on the other, i concluded that it had something to do with the graphics card and not memory or CPU. For a test, try in Flash 8 or older to play with the alpha of an mc (in the timeline) and the same time make an long tween animation of the same mc (for ex. play with the _x and _y again threw the timeline). I am sure you will notice some reduce in the performance of the alpha.I think it has nothing to do with the memory but more with the graphics card, maybe write what kind of card do u use? cheers Kostas 2008/10/7 Glen Pike [EMAIL PROTECTED] Hi, I have inherited an app which is very AS1 / AS2 timeline based and runs on a Linux kiosk box. Debugging the app today, I have noticed that the CPU usage spikes after a while and the whole application slows down. This seems to be when loading data from XML Sockets repeatedly, so I am guessing it may be a memory issue. Is there any way of delving into the system deeper to find out what the problem may be? Does anyone have any pointers to info or articles on what happens with FP memory CPU when you jump backwards and forwards in a timeline which references instances created on certain frames and global / _root objects functions? Does FP9 do memory management for AVM1? Thanks Glen -- Glen Pike 01326 218440 www.glenpike.co.uk http://www.glenpike.co.uk ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- Kostas Plastiras - Master Degree: Multimedia Expert. Web design, Web development Multimedia Production. webplastic.net ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] [JOB] Senior Flex/Flash Developer | Long Island, NY | 110-130k
[JOB] Senior Flex/Flash Developer | Long Island, NY | 110-130k I have an excellent opportunity in New Hyde Park, NY for a Flex/Flash Developer with a Multi-Million Dollar company that is revolutionizing the Health Care Industry. Candidates should be well-versed in ActionScript 2 and 3 (AS2, AS3), Flex Flash. Please be local to the tri-state (NY, NJ, CT) area to be considered. Full details provided to qualified applicants. To be considered, please submit resume and salary requirements to [EMAIL PROTECTED] Thank you, Beau J. Gould Open Source Staffing www.open-source-staffing.com beau at open-source-staffing.com http://www.linkedin.com/in/opensourcestaffing Post free to FlashFlexJobs: http://groups.yahoo.com/group/flashflexjobs ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] working with getPixel32 and setPixel32,
Thank you everyone, i have it working just fine now, and i also grasp the bit operations better too!! youpie! :D props, Seb. Juan Pablo Califano wrote: PD: Sorry, even though the result is the same, to make more sense the second sample should read: var hexaValue:int = 0x9100ff33; var a:int = (hexaValue 24) 0xff; var rgb:int = hexaValue 0xff; var newAlpha:int = 0xcc; copyHexaValue = newAlpha 24 | rgb; trace(uint(copyHexaValue).toString(16));// traces cc00ff33 Using rgb as the name of the var that stores the value of the RGB components, instead of arg. 2008/10/6, Juan Pablo Califano [EMAIL PROTECTED]: Hi, If I haven't misread something, this a = a 1; makes no sense. Unless you're trying to divide alpha by 2, in which case I obviously missed something. If you want to extract the 4 components, you can use something like this: var hexaValue:int = 0x9100ff33; var a:int = (hexaValue 24) 0xff; var r:int = (hexaValue 16) 0xff;; var g:int = (hexaValue 8) 0xff;; var b:int = hexaValue 0xff; var newAlpha:int = 0xcc; var copyHexaValue:int = newAlpha 24 | r 16 | g 8 | b; trace(uint(copyHexaValue).toString(16)); // traces cc00ff33 If you don't bother to get the individual RGB components, just the alpha channel, try this: var hexaValue:int = 0x9100ff33; var a:int = (hexaValue 24) 0xff; var arg:int = hexaValue 0xff; var newAlpha:int = 0xcc; copyHexaValue = newAlpha 24 | arg; trace(uint(copyHexaValue).toString(16));// traces cc00ff33 Also, I'm casting to uint just to display the value in a more meaningful/readable way in the trace, but as long as you don't perform arithmetic on those values, you don't have to (because it's parsed as a bit pattern, not as numerical value, if that makes sense...). Cheers Juan Pablo Califano 2008/10/6, sebastian [EMAIL PROTECTED]: hi Glen, Kudos for the shift 1 operation, knew that was a faster operand. However, this code is still now working, now it simply doesn't change anything... :( var val:uint = getPixel32(x,y); var a:uint = (val 24) 0xff; var rgb:uint = val 0xff; a = a 1; var newval:uint = (a 32) | rgb; setPixel32(x,y,newval); I also tried changing it to say: ... var rgb:uint = val 0x00ff; a = a 1; var newval:uint = (a 24) | rgb; ... since I thought that was an error maybe, but that also doesn't influence the alpha of the pixel... :( Out of desperation I also tried: var a:uint = val 0xff00; var rgb:uint = val 0x00f; a = a 1; var newval:uint = a | rgb; and var a:uint = val 0xff00; var rgb:uint = val 0x00f; a = a 1; var newval:uint = (a 24) | rgb; :( sniff... Setting alpha for the whole MC is not an option for what I am doing. I'm trying to create trails behind things that are moving by having a video-burn like effect; by operating on the pixel level. At the moment I am using code from 'Adventures in AS', but once i have it working I'll encapsulate it and use it in a different project. The original source is: http://flashcoding.blogspot.com/2008/03/small-starfield-with-bluring-effect.html And my current draft-code modification is: package { import flash.events.*; import flash.display.*; import flash.display.Bitmap; import flash.display.BitmapData; import flash.geom.Rectangle; public class Starfield { var mc:MovieClip =new MovieClip(); var screendata:BitmapData; var stars:Array=new Array(); var antal:Number=500; public function Starfield(timeline) { screendata=new BitmapData(320,240,false,0x); var screen:Bitmap=new Bitmap(screendata); mc.addChild(screen); for (var i:int=0;iantal;i++) { InitStar(i); } mc.addEventListener(Event.ENTER_FRAME,this.render); timeline.addChild(mc); } private function MoveStar(index:int) { if (stars[index][0]-160 || stars[index][0]160 || stars[index][1]-120 || stars[index][1]120) { InitStar(index); } else { stars[index][0]= stars[index][0]*stars[index][2]; stars[index][1]= stars[index][1]*stars[index][2]; } } private function InitStar(index:int) { stars[index]=[Number(((Math.random()*10)-5)),Number(((Math.random()*10)-5)),Number((Math.random()/10)+1)]; } private function render(e:Event):void { for(var x:int=0;x320;x++) { for(var