PDA

View Full Version : found awesome scripts that I can't use


TheCheshireCat
04-19-2008, 12:20 PM
Hey everyone

I found this amazing source for flash gallery scripts:
http://www.senocular.com/pub/kirupa/gallery.html

I'm especially interested in getting the SpinGallery one to load from a FLA file.
As it is, its made of .as files only (and a swf), no .fla.

How do I "call" the script from within a .fla file in order to activate it?
I think its the SpinGallery.as that I need to "call", and then that .as file will activate the rest of the script.

Thanks :))

matbury
04-19-2008, 12:38 PM
In the Flash IDE, create a new FLA file and save it.

I the properties inspector window, usually at the bottom of the IDE stage, you'll see a little text input box which is for the document class. Type "SpinGallery" in there and save. Then publish your SWF.

If you want to call the class from the AS window in the Flash IDE, you can do it with:

var spingallery:SpinGallery = new SpinGallery();
adChild(spingallery);

I've only had a quick glance at the class, so I don't know if it'll work how you want it to.

Good luck! :)

TheCheshireCat
04-19-2008, 12:42 PM
Thank you for your reply.

I tried using:
var spingallery:SpinGallery = new SpinGallery();
addChild(spingallery);

in an existing normal fla file that I have, and I get this error:


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SpinGallery$iinit()
at Website13_fla::ClientsPage_27/Website13_fla::frame1()


Could you please help me further?

Thanks

matbury
04-19-2008, 01:10 PM
Ok, have a look at the ZIP folder you downloaded...

There are no images in it.
There's an XML file that points at some directories that don't exist.
The SWF tries to make an HTTP call to a server when you run it, which the Firewall blocks.

It looks to me like you've downloaded an incomplete demo of a package of classes. The code is all there but the assets are missing. I'd recommend going back to the site where you downloaded it and looking for a tutorial to make it work.

TheCheshireCat
04-19-2008, 01:21 PM
Thanks

I downloaded the gallery pics from this page:

http://www.senocular.com/pub/kirupa/gallery.html

And placed them in the right path (inside a folder called images which is in a folder with the FLA and ASs)
And now I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SpinGallery$iinit()
at Website13_fla::ClientsPage_27/Website13_fla::frame1()


I also ran a Google search before posting this thread and found out that this gallery was posted for a scripting battle in some forum. The poster didn't say how to make the gallery work so I assumed it was something very simple that me, being a beginner, didn't know how to do.

RelaxGuy
04-19-2008, 04:25 PM
I downloaded the files, created a new .fla file and set the document class to be SpinGallery. This worked just fine, try that, if you are still getting errors then post them and i'll try to help.

TheCheshireCat
04-20-2008, 10:06 AM
Thanks for checking it for me and for posting the reply.

I changed the FLA's document class to SpinGallery and now I get this error:
(referring to source: SpinGallery.as, Line 1)
1046: Type was not found or was not a compile-time constant: MovieClip.

I believe it refers to this code: (SpinGallery.as)

package {

import flash.display.BitmapData;
import flash.display.GradientType;
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.events.SecurityErrorEvent;
import flash.filters.DropShadowFilter;
import flash.geom.Matrix;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.getTimer;

/**
* A gallery with a rotating carousel of thumbnails for images
* that spin into view when selected
*/
[SWF(width="600", height="450", backgroundColor="#A8A8AF")]
public class SpinGallery extends Sprite {

private var loader:ThumbLoader = new ThumbLoader();
private var status:TextField = new TextField();
private var canvas:RotateViewImage = new RotateViewImage();
private var carousel:ImageCarousel = new ImageCarousel();
private var bitmap:BitmapData;
private static var statusShadow:DropShadowFilter = new DropShadowFilter(4.0, 45, 0x808088, 0.5, 4.0, 4.0, 1.0, 1, false, true);

//.... and so on... (this is just the beginning of the script)


Please help

Thanks

creynders
04-20-2008, 11:09 AM
Change your import block to:

import flash.display.*;
import flash.event.*;
import flash.filters.DropShadowFilter;
import flash.geom.Matrix;
import flash.net.*;
import flash.utils.getTimer;

TheCheshireCat
04-20-2008, 12:59 PM
Hey, thanks for replying.

I changed it to:

package {

import flash.display.*;
import flash.event.*;
import flash.filters.DropShadowFilter;
import flash.geom.Matrix;
import flash.net.*;
import flash.utils.getTimer;

/**
* A gallery with a rotating carousel of thumbnails for images
* that spin into view when selected
*/
[SWF(width="600", height="450", backgroundColor="#A8A8AF")]
public class SpinGallery extends Sprite {

private var loader:ThumbLoader = new ThumbLoader();
private var status:TextField = new TextField();
private var canvas:RotateViewImage = new RotateViewImage();
private var carousel:ImageCarousel = new ImageCarousel();
private var bitmap:BitmapData;
private static var statusShadow:DropShadowFilter = new DropShadowFilter(4.0, 45, 0x808088, 0.5, 4.0, 4.0, 1.0, 1, false, true);

/**
* Constructor
*/
public function SpinGallery() {

// restrict stage scaling
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

// create/add assets
drawBackground();
setupStatusText();
addChild(status);
addChild(canvas);
addChild(carousel);

// set the target of the carousel to be the canvas
// so thumbnails clicked can be loaded into the canvas
carousel.target = canvas;

// define loading listeners
canvas.addEventListener(Event.OPEN, loadingImage);
canvas.addEventListener(Event.COMPLETE, imageLoaded);
loader.addEventListener(Event.COMPLETE, thumbsLoaded);

// listener for previewing image meshes
// when clicking the top left of the screen
stage.addEventListener(MouseEvent.MOUSE_DOWN, renderMeshes);

load("images.xml");

}

/**
* Load XML into the gallery
*/
public function load(url:String):void {
setStatus("Loading thumbnails...");
loader.load(new URLRequest(url));
}

/**
* Event handler; canvas image starting to load
*/
private function loadingImage(event:Event):void {
setStatus("Loading "+RotateViewImage(event.target).name+"...");
}

/**
* Event handler; canvas image loaded
*/
private function imageLoaded(event:Event):void {
setStatus("");
}

/**
* Event handler; thumbnails loaded
*/
private function thumbsLoaded(event:Event):void {
setStatus("");
if (loader.data.length) {

// assign loaded thumbnails to carousel images
carousel.images = loader.data;

// default canvas image to the first image
// in the thumbnails loaded
canvas.showImage(loader.data[0]);
}
}

/**
* Draws the background of the application
*/
private function drawBackground():void {
var w:Number = 600;
var h:Number = 450;

// 2 part gradient split in the center of the screen (ground and sky)
var matrix:Matrix = new Matrix();
matrix.createGradientBox(w, h, Math.PI/2, 0, 0);
graphics.beginGradientFill(GradientType.LINEAR, [0x808088, 0xF8F8FF, 0x505058, 0xA8A8AF], [1,1,1,1], [0x00, 0x80, 0x80, 0xFF], matrix);
graphics.drawRect(0, 0, w, h);
}

/**
* Defines the status text used to indicate loading
*/
private function setupStatusText():void {
var format:TextFormat = status.getTextFormat();
format.font = "_sans";
format.size = 36;
format.bold = true;
format.italic = true;
status.defaultTextFormat = format;
status.autoSize = TextFieldAutoSize.LEFT;
status.textColor = 0x505058;
status.selectable = false;
status.y = 190;
}

/**
* Sets the status message and applies shadow effect
*/
private function setStatus(msg:String):void {
status.filters = [];
status.text = msg;
status.filters = [statusShadow];
}

/**
* Event handler; called when top left corner of app is clicked
* Toggles display of mesh lines in carousel and canvas
*/
private function renderMeshes(event:MouseEvent):void {
if (mouseX < 5 && mouseY < 5){
ImageMesh3D.showMesh = !ImageMesh3D.showMesh;
}
}
}
}


and now I got:

1046: Type was not found or was not a compile-time constant: Event.

referring to lines 68, 75, 82 and 138.

RelaxGuy
04-20-2008, 01:47 PM
Here, I uploaded what I did to make it work. I changed the XML file to a local image file so that the images/ folder wouldn't be needed to make it work.

RelaxGuy
04-20-2008, 02:17 PM
BTW I'm assuming you are trying to write code in the timeline, and since SpinGlalery extends Sprite its made to work without the timeline, thats why you're getting those errors.

creynders
04-20-2008, 05:36 PM
Sorry, my mistake.
this:
import flash.event.*
should be
import flash.events.*

TheCheshireCat
04-20-2008, 07:34 PM
Thanks for helping me :)

Relax:

I understand that your FLA is empty and otherwise unmodified except for the Document Class parameter, which is set to SpinGallery?

I'm trying to make this gallery appear in a certain frame in an FLA that I made, so I think I do need to write some sort of calling function, in order to make it appear in that specific frame only...

I understand what you're saying about how I can't call it using the timeline; Could you please tell me what other way I could call it by? (It would be great if you could give me some keywords or so that I can Google and use to learn how to do this, no need for you to write an explanation :) )

Crey: Sorry but I'm still getting errors after using this, I should probably use both of your advices and both change the import block and the way I use to call the script; Only I'm not sure how to do the latter.

matbury
04-20-2008, 08:03 PM
Hey man, senocular's a pretty helpful guy. Try googling his website for tutorials/docs and if you don't come up with anything, send him a message. I'm sure he'd be glad to hear from you and it'd help him to know what problems you're having.

TheCheshireCat
04-22-2008, 09:48 AM
Thanks!

I did just that and he gave me the solution:
to replace public function... with:

public function SpinGallery() {
if (stage) init(null);
else addEventListener(Event.ADDED_TO_STAGE, init);
}

public function init(event:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);