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.
|
package{
import flash.text.TextField;
import flash.events.MouseEvent;
public class Tag extends TextField{
private var alpha_locked:Boolean;
public function Tag():void{
this.alpha_locked = false;
this.addEventListener(MouseEvent.MOUSE_OVER, mouse_over);
this.addEventListener(MouseEvent.MOUSE_OUT, mouse_out);
}
private function mouse_over(e:MouseEvent):void{
this.alpha = 1;
this.alpha_locked = true;
}
private function mouse_out(e:MouseEvent):void{
this.alpha_locked = false;
}
override public function set alpha(a:Number):void{
if(!alpha_locked) super.alpha = a;
}
}
} |
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 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.
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.
|
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</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 these
import flash.system.LoaderContext;
import flash.net.URLLoader;
import flash.net.URLRequest;
// create your request to the resource
var request:URLRequest=new URLRequest("http://www.somesite.com/someresource");
// create the loader to do the actual load
var loader:URLLoader=new URLLoader();
// this is the loader context
var 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); |
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.
So first off you need to import some stuff
|
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
import flash.net.URLVariables; |
(more…)