Getting cubic bezier drawing API’s to work in my projects
There are several examples of drawing methods that draw a cubic bezier line that can be changed interactively by moving two control points and two anchor points, which is exactly what I needed for a project. An example of one is HERE. This one is by Robert Penner, from his book: Robert Penner’s Programming Macromedia Flash MX”
I couldn’t figure out why I could not get these functions to work in my own pieces, even when I exactly duplicated the structure of his flash movie. They would work in his, but not in mine.
The first frame of the movie has two “include” references in it, to two actionscript files containing all the common functions for his drawing methods.
#include "drawing_api_core_extensions.as"
#include "bezier_draw_cubic.as"
I knew the paths to the includes files were correct, since including the first one of them, by itself, gave no errors, and including the second one generated errors about itself:
For example, line 45 of bezier_draw_cubic.as contains:
Math.intersect2Lines = function (p1, p2, p3, p4) {
var x1 = p1.x; var y1 = p1.y;
var x4 = p4.x; var y4 = p4.y;
The first of many errors you get when attempting to check the syntax on the frame that contains the 2 includes is:
“**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 45: There is no method with the name ‘intersect2Lines’.”
After puzzling over this for hours, I searched the flash newsgroups, I came across this thread:
___________________
From: “kellyrambow”
Newsgroups: macromedia.flash.actionscript
Date: Tue, 6 Apr 2004 18:58:25 +0000 (UTC)
Subject: Math form works in one place, not another
I have a small calculation form that I want to put inside of a movie clip off
the main timeframe of my site.
This script works in a separate flash file, but when I use the same field name
& script code within my main movie, it no longer works.
here is my code:
loan = 0;
rate = 0;
num = 0;
//
_root.onEnterFrame = function( ) {
payment = (math.round((loan*rate)/num)+(loan/num));
};
All I need is for this calculation to work in my website inside of a movie
clip, but when I bring it into the timeline within my movie clip, it no longer
works.
What could I be doing wrong?
Please help!
——
From: “Jack.”
Newsgroups: macromedia.flash.actionscript
Date: Tue, 6 Apr 2004 21:38:54 +0000 (UTC)
Subject: Re: Math form works in one place, not another
use “this”, to tie the code to the clip timeline –
this.onEnterFrame = function( ) { .. }
hth
——
I needed to change the path on all the math functions in the “bezier_draw_cubic.as” file to associate the methods with the timeline of the clip they were in.
So line 45 became:
this.Math.intersect2Lines = function (p1, p2, p3, p4) {
var x1 = p1.x; var y1 = p1.y;
var x4 = p4.x; var y4 = p4.y;
This got the functions recognized, but they still did not entirely work.
It turned out that the publish settings had to be set at Flash Player 6 and ActionScript 1.0 for everything to work perfectly.
Here are some links to other cubic bezier drawing articles and code:
Approximating Cubic Bezier Curves in Flash MX by Timothée Groleau
the forums for discussion on Robert Penner’s book