This one can be pretty nifty. In my certain case I had a bunch of on screen items that I continually updating their alpha property but when there was a mouse over I didn’t want to update that property anymore and peg it right at 1 so it stood out. In this case it was a text field so here is a class with the not important parts taken out.
The magic happens with the super.alpha, super which refers to the parent class that Tag inherits from. It checks the alpha_locked variable and if things are ok it sets it, otherwise it’s ignored. Then the alpha locked variable is controlled by the MouseOver and MouseOut events.
I’ve run into this problem a few times I want to rotate and object by an arbitrary point. First off actionscript doesn’t let you change you point from which you rotate when you change the rotation attribute of an object. By default when you rotate using the rotation attribute flash rotates the objects at it’s index point (0, 0). Simple solution move the object so it’s center point is at the index point of it’s container move clip then rotate it, then move it back it’s original position. To make things easier you can of course wrap this up in a function inside of an object or use this snippet.
function rotate(item:DisplayObject, angle:Number, point:Point) {
var matrix:Matrix = item.transform.matrix.clone();
matrix.translate(-point.x, -point.y);
matrix.rotate (angle*(Math.PI/180));
matrix.translate(point.x, point.y);
item.transform.matrix = matrix;
}
Simple enough to use just pass the function the moveclip you want to rotate the angle just like you would with the rotation attribute and the point from the index point that you want to rotate your clip.
I’ve always wanted to write a flash game. It’s been so intimidating not just the having to learn flash but the how do I make a fun and addictive game. Well the first hurdle I think I’ve gotten over. Recently I’ve had to opportunity to learn flex. It’s kind of like flash, well at least I know actionscript 3 fairly well. So l sat down last week and started playing around with things and let me say all the shit I talked about flash I take it back it’s pretty damn fun to program, like python there is a whole world of things you can do with it. I’ve made some fun little things with papervsion3d which in itself is just freaking amazing so more on that later. After playing with it[papervision] really got to wanting to build a sudo 3Dish flash game, I quickly learned that papervision was probably overkill for what the simple thing I want to do so instead I’ve decided to go with a simple Isometric view game based on sprites. I have no artistic ability. I did get my friend to do some artwork so I can thank him for the grass, dirt and little hut, but until I con someone into doing a whole lot of art for free I went with some free isometric sprites I found here.
So after roughly two days of fleshing out an isometric view type thing I’ve got this.
Click on the flash app then use the arrow keys to move the little dude around. I’m still very far from a game but this is a great start.
Credit cards are great you can cover some of your expenses if you come up a little short and as long as you can pay them off in a reasonable amount of time they are great deal.
If you use them in that way, on the other hand, you can use them to live beyond your means, you didn’t need that 52inch LCD 1080p 120hz TV but you sure as hell wanted it. I sure as hell wanted that LCD TV.
As a newly graduated college student I found how far my money really does go. It’s not that far. Especially when you have a credit card payment to pay, of course I could of just paid the minimums, but use the debt calculator and you can see how much of a bad idea that really is. Moral of the story if you can pay more than the minimums do it, even if it’s 5 bucks more do it. It makes a huge difference in the long run. Remember you’re borrowing money so they have to get a pay off for letting you borrow it, that’s where the interest comes in. Take for example if you have the average interest rate or 12.99% APR and you have a 10k balance, you are going to pay 108.25 in interest. That sucks.
I finally got mine paid off it was a huge relief of course now I have to pay off the student loans. That’s another story all together, I took out way more than I should of, I’ll pay for it. For the next 10 years.
In the mean time heres a quick calculator for your credit card debt it’s still beta so if you start playing with the numbers too much you can have it go into an infinite loop, which is no fun if that happens force quit/end task your browser and start again. I’ll work on the calculator more as I go along, as well has a nifty calculator for student loans and home mortgages since I’m hoping that I can build up my savings and get a house in the next few years.
Note: I’m not an accountant I made this tools for myself, it’s not going to be spot on but it should be pretty damn close.
Ahhh a sandbox violation if you are stating to pull content from other sites or even pull external content period to your SWF get used to them. They really do suck and at first it is overwhelming when you get them all the time, take it from me though after some time getting your hands dirty with Actionscript these things become a thing of the past.
First up, why do I get these errors?
Easy it’s to protect everyone on out there in the tubes.
These cross domain scripting errors happen because code from one domain is not allowed to modify content from another domain. This is so that say you are browsing your bank’s site doing your normal bank things but at the same time you are also browsing Matt Evilphen’s site. He has some code on there that detects that you are your banking site and transfer all your money to his account, oh no, you’re broke. Well fortunately you cannot do this, oh course there are million other ways to have you bank account drained, this is not one of them.
It’s very strict too. www.charlescfenwick and blog.charlescfenwick.com are not the same and neither is www.charlescfenwick.com:8080
So how does one get around this?
well first off you need a crossdomain.xml file on the server which the remote is being accessed from.
<?xmlversion="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy><allow-access-fromdomain="*"/></cross-domain-policy>
This is an example of course you’ll probably want to change the * to what ever domain the swf is coming from.
then as usual load your content, but take special note of the LoaderContext class
// don't forget theseimport flash.system.LoaderContext;
import flash.net.URLLoader;
import flash.net.URLRequest;
// create your request to the resourcevar request:URLRequest=new URLRequest("http://www.somesite.com/someresource");
// create the loader to do the actual loadvar loader:URLLoader=new URLLoader();
// this is the loader contextvar context:LoaderContext = new LoaderContext();
// set the check policy flag in the loader context
context.checkPolicyFlag=true;
// add the handler for when the event completes
loader.addEventListener(Event.COMPLETE, completeHandler);
// retrieve the resource
loader.load(request, context);
I gave it a shot and ended up with some ok results there is still a lot that can be done to improve things.
Using just the closest color ends up with ok results but when there are large areas of an almost solid color the results are less than desirable. These can be seen in the closestColor gallery.
To further extend things I created an algorithm that tries to insure that a given image doesn’t appear more than once in a given radius. This seems to work really except when two tile images are fairly close together. These can be seen in the Closest Color + Minimum Distance 16 gallery.
An RGB color can be thought of as a coordinate in a 3d Cartesian space. So to find the distance between two colors it is nothing more than find the distance between two coordinates in a 3d space.
(R1, G1, B1) and (r2, G2, B2)
SQRT((R1-R2)^2+(G1-G2)^2+(B1-B2)^2)
very easy now lets have MySQL do all the work and find the best match.
Imagine a table called images with columns r, g, and b where r, g, and b are the average colors of that particular image and below {R}, {G}, and {B} are the average RGB values of the source image rectangle we are comparing.
SELECTSQRT((images.r-{R})*(images.r-{R})+(images.g-{G})*(images.g-{G})+(images.b-{B})*(images.b-{B})) as score, images.id as id, images.location as location FROM images ORDERBY score ASC LIMIT150;
This will return a nice little list of the 150 closest matches by color. 150 were returned so at a later step in the mosaic creation process we can do a little more processing to the mosaic matching results.
I need images and I mean lots of images. In my head I can only see having more images to make up the tiles the better. Of course every time I add an image it makes searching for the correct image a little slowewr, but ups the chance I may find a better match. (more…)
Seems like there have been more and more photo mosaics popping up on digg lately. I figured I could make one, but one up the other people and actually write the program to make them instead of using some program I found online. (more…)
One of the things I find annoying when I’m looking for a quick solution to some programing problem is that people don’t post everything you need to get going such as the import lines, to you know, actually get their snippets of code to work.