I programmed a simple class which informs you when object property value is changed.
Sample above shows how coordinate information is updated when user clicks button for setting new random coordinate. Sample is included in source, along with asdoc.
When you try to interact with cube material to determine which face has mouse over it, it is impossible to do it with adding OBJECT_OVER listener to cube.
Solution
Basic thing is that instead of putting listener for mouse over, we listen to mouse move. Or if we put it in perspective of listeners in cube with which we are working, OBJECT_OVER listener is replaced with OBJECT_MOVE listener.
You will need one variable for holding current cube face on which mouse is over:
Finally in cubeMoveHandler you will need to check if face on which mouse is over has changed. That is neccessary so that event only occur once. That way we simulate OBJECT_OVER method but which works will cube faces. Here is cubeMoveHandler method:
privatefunction cubeMoveHandler( event:InteractiveScene3DEvent ):void{//Check if mouse is over another cube faceif(this.currentCubeFace != ( event.target.name + "" + event.face3d.material.name)){this.currentCubeFace = event.target.name + "" + event.face3d.material.name;
this.textField.text = "Target: " + event.target.name + ", face: " + event.face3d.material.name;
}}
Problem comes up when you dynamically add TextField with special font to your movie. You can create empty dynamic TextField on stage and embed fonts in it. Then you have global access to that font from TextFields through your classes. But by default you have No Bitmap antialiasing turned on. So your font looks distorted.
Solution
Assuming you embedded fonts which you will use, to fix this problem there is class AntiAliasType. TextField contains property antiAliasType which you will need to set.
var format:TextFormat = new TextFormat( "Calibri" );
textField.text = "Some text.";
textField.embedFonts = true;
textField.antiAliasType = AntiAliasType.ADVANCED;
textField.setTextFormat( format );
So, in loaded SWF constructor you would register for ADDED_TO_STAGE event, and then you can use stage object. Simple enough.
Why do you need this? Mostly when having your application in full browser window. When resizing occurs you would want to resize or move objects in you loaded SWF. Imagination is the limit.
Problem is that some browsers won't refresh data got from database. They cache query results. Example:
var url:String = "http://www.example.com/get_data.php";
var req:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.load( req );
So with this you can load results from php document. But when you ask for results again, some browsers (I noticed IE) will cache results and you will get same results. Refreshing the page and loading your application again will help. But you don't want user to refresh page, don't you?
Solution
Solution is pretty simple. In order to get new result you must confuse browser. You can confuse it by giving it new url to load. So, on our original url we will give it some meaningless sufix which won't do anything other than generate new url.
This way on every refresh you get different number as sufix, making your url unique.
Finally your code should be:
var url:String = "http://www.example.com/get_data.php";
url += "?randomVar=" + Math.random();
var req:URLRequest = new URLRequest( url );
var loader:URLLoader = new URLLoader();
loader.load( req );
When I started out with programming I looked at commenting my code as unnecessary job. But back then, I worked with small programs. Then I was in a situation when I couldn't remember what classes are for what, and what some methods are doing. So I started commenting my code with simple line comments (//) or block comments (/**/). That was good enough for couple of years. Code was good, my methods, variables and classes were labeled. I wrote myself some kind of standard for code commenting. After that I wanted to have some documentation for my code. Then I opened Excel and wrote 3 columns. One was for methods name, second was for class name, and third was for method description. Now, I'm in stage when I don't have time or the motivation for double writing comments. That led me to discovery of ASDoc.
What is ASDoc?
Most simple explanation is that it is a tool for making documentation of your comments which are written in specific formatting. You comment your code with some explanation, some tags, and ASDoc will generate html documentation.
ASDoc formatting and tags
Formatting
It is really simple to format your comments for ASDoc. It's basically like writing block comments except you have one character more. One simple example is this:
/**
* Your description goes here.
*
* @tag Tag description goes here.
*/
Like I said before, your comments consist of explanation and tags. Important thing is that your first sentence have to describe your complete code (method, class, function or variable). I'll explain this on example. Let's say you commented your public function. That function will be visible in your documentation. Under your class there will be list of function on top. In that list you will find your function and short explanation which is exactly your first sentence. Sentence ends with period followed by delimiter (space, tab, line break).
You can have as much sentences as you like, and all of them will show in detailed description of the code you commented.
Note:
Notice asterisk (*) and one white space is before every new line. It is common practice to put it like this. It will make your code more readable for you and needed for ASDoc tool to parse your comment.
Also I like to save some space and organize things, so when not needed, I write one line comments like this:
/**My one line description*/
Tags
Except describing your part of code, you can give it some "special abilities", called tags. Tags will put your tag explanation in special place and have it specially formatted in generated documentation. That will make your documentation more readable and more structured.
Note:
In section below, I gave a link to what Adobe calls "complete list of ASDoc tags". It isn't complete list! The best way to find tags which you want is to go to Adobe documentation, find some piece of documentation you like, then go to Flash classes (where you installed Flash) and open that class in which you found that piece of documentation, and read out that tag and it's formatting.
If you don't know what FlashDevelop is, check out FlashDevelop - essential developing environment.
Since I like working with FlashDevelop, I wanted to integrate documentation generation in it.
First you have to download and install FlexSDK if you don't have it. This is needed since ASDoc is now part of Flex SDK.
Next you have to configure your FlashDevelop to connect to ASDoc in FlexSDK. Read tutorial here. (don't forget to remove line breaks and " in tag)
That's it. Now when you are done writing your comments, just select ASDOC button from toolbar and your documentation is generated.
Note: One other thing is that you have to have proper folder structure for generating you documentation. My folder structure is on the picture. This is needed because when you choose to generate ASDoc it will create separate folder in which it will store all documents needed for your documentation. In src I put my source code, in deploy goes final product, and in root is my FD file. Then when I click on ASDOC button to generate documentation, it will create doc folder in the same directory as your FD file. If you follow their tutorial and input their code in Toolbar.xml, it states path to your source code folder. I find this structure as the best way of keeping your files neatly organised. If you still choose to have your own structure, just replace -doc-sources path in Toolbar.xml.
Final thought
Well ASDoc made my life easier. Now when I work on a project, I have complete description of my classes in one place. It really ensures you if you need to return to some project after a while.
Recently, I got my head around a problem of LocalConnection not working with sending data that is not simple data. I couldn't send my own classes through it.
I found a solution with registerClassAlias. You can read more about it: registerClassAlias()
The example above is a demonstration of using registerClassAlias with LocalConnection, and sending custom class named TextData from Main.swf to LoadingSWF.swf.
I created a simple class which allows you to convert MovieClip to button which has ability to be in clicked state, and also follows which button is active. Detailed description will be coming in later.