April 30, 2004

PHP Alternating Color Table Rows for Drupal or Dreamweaver sites

This is based on the great tutorial by phpfreak at phpfreaks.com For a more complete explanation of this, take a look at his article.

The main variation I have made here is to adapt it for the drupal database and to separate the HTML more from the PHP to make it easier for designers to alter without needing to escape the code characters: a big source of errors for those of us who are not writing code day in and day out.

This will also work well dropped into a Dreamweaver-created php site - just change "nid" and "title" to whatever fields you want to display instead, and use the query dreamweaver generates when you define a recordset.

If you are new at this, it may go more smoothly if you first create a dynamic site in Dreamweaver, then create a dynamic table with whatever fields you want, THEN add in the additional code to generate the colors by comparing that file and this.



NOTE: If using this in a Drupal static page, leave off this line: <?php 


mysql_connect ('localhost', 'username', 'password') ;
mysql_select_db ('MyDatabase'); ?>


<HTML>
<HEAD>
<TITLE>Node titles browser with alternating colored rows</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>

<BODY>



<table border='0' cellpadding='4' cellspacing='0'><TR><TD>No.</TD><TD>Title</TD></TR> 

<!--  **** color variables and initial row count ***-->
<?php  
$color1 = "#CCFFCC"; 
$color2 = "#BFD8BC"; 
$row_count = "0";  

$NodeTitles = mysql_query("SELECT nid, title FROM node WHERE type = 'story' ORDER BY title ASC") or die (mysql_error()); 
while ($row = mysql_fetch_assoc($NodeTitles)) { 
$Nid = $row["nid"]; 
$Title = $row["title"]; 
$row_color = ($row_count % 2) ? $color1 : $color2; 
?>
<tr> 
<td width="110" bgcolor="<?php echo $row_color; ?>"> 
<?php echo $row_color; ?></td> 
<td bgcolor="<?php echo $row_color ?>"> 
<A href="http://your.drupalsite.com/node/view/<?php echo $row["nid"]; ?>"><?php echo $row["title"];?></a>
</td></tr>

<?php
    $row_count++; 
} 
 ?>

</table>

</BODY>
</HTML>
<?php
mysql_free_result($NodeTitles);
?>
Posted by ellen at 1:33 PM

April 25, 2004

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

Zoode Geometries 2D

the forums for discussion on Robert Penner's book

Posted by ellen at 2:57 AM

April 24, 2004

Particle-based Water stream effect in Flash

Some examples of using a motion-tweened shape as a particle.
Click here to see some variations.

This is based on a particle fire example created by Anton Volkov

To use, simply drag the symbols from the stage into your own flash document.

Note: the duplicateMovieClip() function used in these old files is outdated. Here is an example of a corrected FLA file [Download updated file]
Posted by ellen at 12:57 AM

April 16, 2004

Upgrade your Subcategories Plugin

A few days ago, I deleted 2 MovableType categories that did not have any entries in them. The next time I tried to publish an entry, I got this error:

Can't call method "label" without a package or object reference at plugins/sub_cats.pl line 67

It turns out that the Subcategories plugin could not deal with non-continuous numbering of category id's. Deleting the two categories caused gaps at #3, and #11.

I did a quick search and came up with this page:
Comments on SubCategories version 0.2.1

I installed this version, but it did not fix the problem - I continued to get errors. So I went into the database, and manually inserted two new rows in the table mt_category, and set the category_id for them to 3 and 11.

Later on I found that there is an even later version, and will be installing that soon.

Posted by ellen at 7:51 PM

Accessing the main timeline from a loaded SWF on another level.

I have a flash file which loads an external SWF (call it external.swf) into the main timeline, on level 10. In this case, using _root or _parent to call the symbols on the main timeline will not work, since _root or _parent would refer to items on _level10.

The main timeline also contains a movie clip called "swapColors_mc" with two frames called "red" and green".

To control the color change of swapColors_mc by clicking a button in external.swf once it is loaded, open "external.fla" (the original flash file from which external.swf is created) and add this actionscrip to the button:

on (release) { _level0.swapColors_mc.gotoAndPlay("green"); }
Posted by ellen at 6:26 PM

April 9, 2004

Drag the ends of a stretchy curve in Flash

I've been working on a simulation of a fire extinguisher in Flash. One necessary feature is the ability for the viewer to aim the end of the hose at different targets. I had seen plenty of mouse-trail following effects, with particles following the mouse's direction, and some might almost have worked for the hose.

But what I really wanted was the ability to pick up one end of a line, and move it, exactly like moving the ends of a bezier curve in Adobe Illustrator.

It turns out there are several functions that let you do just that. A detailed description of them is HERE

A very rough draft of the fire extinguisher project is: HERE

It isn't a finished piece by any means, but demonstrates the bezier-curve hose effect nicely.

Posted by ellen at 6:11 PM

April 1, 2004

Macromedia Extension Manager unexpected quit on startup

After installing Panther and Macromedia Studio MX 2004 and using them for about 2 weeks, Macromedia Extension manager suddenly stopped working. Every single time I would try to start it, it would unexpectedly quit. It turns out the solution was to go into

~user/Library/Application Support//macromedia/dreamweaver MX 2004/configuration/extensions/

and disable all extensions by moving them to the "Disabled folder". I had to also restart the machine before EM got going again. Then you can test each extension by moving it back to see if Extension Manager still works.

Many thanks to DC_Kyote on the Macromedia Dreamweaver Support forums for this one.

Posted by ellen at 2:28 PM