Monday, August 29, 2005

onLoadInit class woes

Ive been wrestling with an actionscript 2 problem for a while now, how to load a movie from within a class and pass data from the class to the movie. All of my attempts failed miserably and it was one of those nagging problems that you just know has a simple answer. Here's what I found.

Heres my code:

public function FormBlock(formXML:XMLNode, target:MovieClip) {
formOBJ = this;

// create empty movie clip to load the swf into
container_mc = target.createEmptyMovieClip("formBlock"+ID, DEPTH);
container_mc.formOBJ = formOBJ;
var mclListener:Object = new Object();

//the onLoadInit event just traces out the XML we want to send to the loaded movie
mclListener.onLoadInit = function(target_mc:MovieClip) {
trace("movie loaded");
trace("formXML "+target_mc.formXML);
trace("formXML "+target_mc._parent.formXML);
};

var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("forms/"+TYPE+".swf", container_mc);
}
You can see that im looking to trace out the data from within the loaded movie. Unfortunately this doesnt work. What you need to do is very simple, although I scratched my head for a while. What you need to do is send the data to the Listener object before the onLoadInit:

mclListener.formOBJ = formOBJ;
var mclListener:Object = new Object();
mclListener.onLoadInit =
function(target_mc:MovieClip) {
target_mc.formOBJ =
this.formOBJ
};

this works well. But over the past couple of days it dawned on me that you dont need to create a new listener Object (slaps forhead). You just use the class instance as the listener like this:

var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(this);
image_mcl.loadClip("forms/"+TYPE+".swf", container_mc);

So problem solved? Not quite. What we need to do now is make the onLoadInit event a method within the class so the complete code is now:

public function FormBlock(formXML:XMLNode, target_mc:MovieClip) {
formOBJ = this;
container_mc = target_mc.createEmptyMovieClip("formBlock"+ID, DEPTH);

var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(this);
image_mcl.loadClip("forms/"+TYPE+".swf", container_mc);
}
public function onLoadInit(this_mc:MovieClip) {
this_mc.formOBJ = this.formOBJ;
this_mc.TYPE = this.TYPE;
trace("movie loaded");
trace("formOBJ "+this_mc.formOBJ);
}

Wednesday, August 24, 2005

Baby Brookfresh is born

My baby son arrived at 1.40am Sunday morning. So I havent really had a chance to post anything. He's a healthy 7lb and both he and Lisa (Mrs Brookfresh)are well.

We still arent into any sort of sleeping pattern yet so posts may be few and far between. Ill do my best.

I managed to grab an hour on WG today and I added the ability to place blocks of colour on the site. You can see an example of a block of colour behind the text on the homepage. I also added the ability to place swf files too, although this uses the image loader class I wrote so its really nothing new.

I think I'm happy with how the site is designed now. It's taking shape at last. I always find it difficult to design my own stuff. Take the original www.brookfresh.co.uk for instance. After three years this is the first design Ive been happy with, I think we're still getting over 10k hits a month too. Talking of Brookfresh.co.uk there should be another podcast due any day now.

The front end mechanics of WG should be done today once I write the 'add form element' class so I can then concentrate on the Admin area. or as I like to call it 'the hard bit'.

I have registered to attend the launch of Macromedia Studio 8 in Manchester. This should be interesting, I havent had chance to attend one before. I may even buy the app on the day so fingers crossed for a discount eh!

Saturday, August 20, 2005

Its Saturday and im still on my Computer

Ive done the hard bits of the front end to Website Generator (WG from now on) now. And I've redesigned the WG corporate website using the WG itself. I used a photo taken by me on my new Kodak LS755 camera, which I purchased recently so I can photo my Baby, (when it decides to arrive, Due any second now.)

Ive written the menu system using a single AS2 class, if anyone's interested i can add a link to the code, I don't mind sharing my code with most people. The menu class is extremely re-usable in that it allows you to add menus and submenus from data loaded from a simple XML file. If an XML node in the file has children then the class uses this as the sub menu. You can set the _x and _y properties the colours, text and even change the style of the menu you create. Ive limited the number of menus the WG allows you to create to three, head menu, main menu and footer menu with a single level of submenus for the main menu. Does that make sense?

Its the weekend now so ill not be working on the WG, ill be keeping myself busy on my extension otherwise Ill only be pacing the floor waiting for my Baby to be born.

Friday, August 19, 2005

Hello there

Welcome to my Blog. Ill try my best to keep this up to date.

Im currently putting together my own creation called Website Generator. Its actually a re-build of a project I started many years ago. The Website Generator lets normal ppl design and maintain their own small website, you choose a template much like you do here on blogger, then you add your text and pics. There are various types of forms to choose from too. Im rewriting it using AS2 classes i also redesigned the way it works, this time allowing for easier modification.