Posts Tagged ‘experiment’
Overview
To find the distance of any two points on an axis is easy, just subtract them. But what about when you have to find the distance of something not on the axis (a diagonal)? Find the distance between any two points with the Pythagorean theorem. This is an old problem we can look to history and find the Pythagorean theorem and Pythagoras, the Greek we’ve named this after. His theorem states that ‘In any right triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).’

You may remember it as the formula you memorized in geometry or algebra class ‘a squared plus b squared equals c squared’

Okay, but how does that help in flash? You want to find the distance between point
and point
. Well
would be the distance between the two points. We know the formula, solving for c.
1
| c = square root of (a^2 + b^2) |
.

1
| c = Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)); |
is the square root function, so
.
computes and returns the square root of
.
is the power function, so
(4 squared).
computes and returns
to the power of
.
You say I remember using this for triangles and stuff, I just want to know the distance between two points, there’s no triangles.
Well, there actually is a triangle we can draw. Go from your first, along an axis (this makes one side), and the other point, along the other axis (this is another side), and you’ll see that the distance you’re looking for is the third side of the triangle (the hypotenuse).
Example
Here’s a quick interactive flash file to show the idea.
Actionscript
1 2 3 4 5 6 7 8
| xmid = Stage.width/2;
ymid = Stage.height/2;
a = _root._ymouse-ymid;
b = _root._xmouse-xmid;
c = Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2));
feedbacka.text = Math.round(a);
feedbackb.text = Math.round(b);
feedbackc.text = Math.round(c); |
Download
As usual, here’s the source flash file (flash 8 compatible) to take a look: distance.fla

Author: Evan Mullins | Filed under: tutorial
Tags: actionscript, as2, download, experiment, flash, interactive, open source, tutorial
Overview:
Using what I learned with the Actionscript Javascript Communication Tutorial, and pushing it a little further I’ve set up this example of how flash renders html and css. This is basically a wysiwyg (What you see is what you get) html editor! Natively flash only handles some html and css. Many people have enhanced it’s capabilities with projects and Classes, but I made this to show what is accepted by default as far as html and css is concerned. I know there are specs and many lists about what will work, but to me the best way to know if my code will work is to try and see…
I’ve made this app so if I have a question, I just paste in my html/css and send it to the swf to see it rendered live. This saved me a few headaches, so I thought other might enjoy it as well… So here it is.
Example:
Render your own html and or css in flash. htmlToFlash.html
Here is the flash rendering of some dummy text as html with css applied

Here’s the html interface where I paste in the html and css.

Each supported css property has a corresponding actionscript property, but the naming convention is a little different for css in actionscript. Each actionscript property name is derived from the corresponding CSS property name; the hyphen is omitted and the subsequent character is capitalized. So for example: ‘font-weight’ becomes ‘fontWeight’.
Download:
Here’s the open source files if you want to get your hands dirty.
Let me know if you improve this or even have any questions about it!
Again, note there are only certain HTMl and CSS supported by flash, follow the links for more info.
HTML supported by Flash and CSS supported by Flash

Author: Evan Mullins | Filed under: portfolio
Tags: actionscript, as2, css, download, experiment, flash, html, javascript, open source, tutorial
Gives feel of perspective and depth by reacting to mouse movements. The effect is parallax, read more…
The city images are very choppy and ugly, I know, it’s just a test.
Sample Actionscript. This in on one of the buildings which are separate movie clips. Adjust the equation for different effect.
The basic formula is as follows: this._x = _root._xmouse / (speed) + transform
1 2 3
| onClipEvent (enterFrame) {
this._x = _root._xmouse/7 - 50;
} |
Update: Here’s a similar effect achieved by just negating the relation between the mouse and the building movie clips.
1 2 3
| onClipEvent (enterFrame) {
this._x = -_root._xmouse/7 - 50;
} |
Download Source Fla File

Author: Evan Mullins | Filed under: portfolio
Tags: 3D, actionscript, animation, as2, download, experiment, flash, open source
Overview:
Flash give publishers the opportunity to customize the right-click menu which pops up in the swf file with a context menu item in actionscript.
ContextMenuItem
1
| ContextMenuItem(caption:String, callbackFunction:Function, [separatorBefore:Boolean], [enabled:Boolean], [visible:Boolean]) |
Creates a new ContextMenuItem object that can be added to the
array.
Steps:
The menu item has a caption, which is displayed to the user in the right click menu. It also has a a callback function handler by naming the function in the code to be invoked once the menu item is selected. It then has three boolean values which specify whether the item has a separator before it, is enabled, and is visible.
To add a new context menu item to a context menu, you simply create the context menu items and then push them into the customItems array.
You can enable or disable specific menu items, make items visible or invisible, or change the caption or callback handler associated with a menu item at any time.
In the example here the menu items about clearing and rewriting the text are set to toggle each other, so you can’t rewrite the text if it hasn’t yet been cleared and vice versa.
To further customize the context menu flash allows us to hide the built in items in the menu with hideBuiltInItems(). This hides all the built in item from view (except ‘settings’) by setting their visibility to false.
Example:
Actionscript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();
var ccs:ContextMenuItem = new ContextMenuItem("Visit Circle Cube Studio", visitCCS, false, true, true);
var pog:ContextMenuItem = new ContextMenuItem("Visit Interactive Flash Portfolio", visitPOG, false, true, true);
var ct:ContextMenuItem = new ContextMenuItem("Clear Text", clearText, true, true, true);
var rw:ContextMenuItem = new ContextMenuItem("Rewrite Text", rwText, true, false, true);
var mt:ContextMenuItem = new ContextMenuItem("Move Text", moveText, false, true, true);
myMenu.customItems.push(ccs, pog, ct, mt, rw);
_root.menu = myMenu;
function visitCCS () {
getURL("http://blog.circlecube.com", "_blank");
}
function visitPOG () {
getURL("http://www.circlecube.com/test/", "_blank");
}
function clearText() {
myText = "";
ct.enabled = false;
rw.enabled = true;
}
function rwText() {
myText = "Rewrite: \nRight-click to see the customized menu";
ct.enabled = true;
rw.enabled = false;
}
function moveText() {
theText._y += 10;
} |
Download:
Download the Zip file (right-clickMenu.zip)

Author: Evan Mullins | Filed under: tutorial
Tags: actionscript, as2, download, experiment, flash, interactive, open source, tutorial, web design
As seen at Flashden. I’ve fixed it up a lot and made it much easier to incorporate into your own files.
A link list. Vertically scrolling list of links or just words. Scrolls and wraps automatically and interactively. Reads an external XML file containing just titles and paths and creates an interactive click-able link list!
Download the source files (linkList.fla, cats.xml, linkList.swf): Link List at Flashden.
Other Circlecube Items at FlashDen


Author: Evan Mullins | Filed under: portfolio
Tags: actionscript, animation, as2, download, experiment, flash, flashDen, interactive, open source, xml