PDA

View Full Version : Button Class



snozbunny
December 26th, 2007, 11:36 PM
Hi everybody. I'm working on making my buttons more... OOPie? It's killing me. I used a target to load the movie clip I'd like to dump images into so I can make buttons the way I know they're supposed to be made but as hard as I try I can't add things to that movie clip from within that same file.

I need a life line. :link:



package components
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.display.MovieClip;

public class ImageLoader extends Loader
{
private var target:Object;
private var playup:String;
private var playover:String;
private var objx:int;
private var objy:int;
private var _playbtn=new MovieClip;

public function ImageLoader(target:*, playup:String, playover:String, objx:int, objy:int) {
this.target = target;
this.playup = playup;
this.playover = playover;
this.x = objx;
this.y = objy;
this.target.addChild(_playbtn);
init(this.playup);
}
private function init(loadimg):void
{
this.contentLoaderInfo.addEventListener(Event.COMP LETE, completeHandler);
var request:URLRequest=new URLRequest(loadimg);
this.load(request);
}
private function completeHandler(event:Event):void{
var _image:Bitmap=Bitmap(this.content);
#### "this.target + _playbtn" .addChild(_image); ????
}
}
}

453.0
December 27th, 2007, 06:40 AM
^ Huh, that's a bit messy, I'll try to take a closer look in a few hours. Anyways, why do you extend Loader instead of Sprite or MovieClip ?

snozbunny
December 27th, 2007, 10:11 AM
I just started learning AS3. Forgive me if it's messy.

snozbunny
December 27th, 2007, 11:16 AM
I tried it without a loader class and it won't function at all. I assume that's because I'm loading a external .png instead of items from the library. I was attempting to make the entire flash application out of .as files and .png files so I can re-use the code or pick and chose the interface items as needed. I can only hope there's some easy way to make buttons that I'm unaware of.

GrndMasterFlash
December 27th, 2007, 11:27 AM
public function ImageLoader(target:*, playup:String, playover:String, objx:int, objy:int) {
this.target = target;
this.playup = playup;
this.playover = playover;
this.x = objx;
this.y = objy;
this.target.buttonMode=true;
this.target.addEventListener(MouseEvent.CLICK, this['btnclick']);

var _playbtn=new MovieClip;
this.target.addChild(_playbtn);
//did you set up the linkage in your library???
init(this.playup);
}
private function init(loadimg):void
{
this.contentLoaderInfo.addEventListener(Event.COMP LETE, completeHandler);
var request:URLRequest=new URLRequest(loadimg);
//you have a misspelling here ^ "loadimg, and if your loading an image
//you need to give it and extention, plus your paramater should be a string
//so put some quotes around it like URLRequest("loading");
this.load(request);
}
private function completeHandler(event:Event):void{
var _image:Bitmap=Bitmap(this.content);
//what is (this.content) reffering to???
//impoper syntax on line below
#### this.target and _playbtn? .addChild(_image);

snozbunny
December 27th, 2007, 12:15 PM
I'm trying to avoid using the library. That's why I'm trying to do it in this manner. So the _playbtn is actually a MovieClip I created in the class.

The URLRequest is a-ok. It's calling on loadimg and that references a url defined when I call the class.

The this.content is.. I'm not sure. I can't get it to work without that for some reason.

The last bit of code was what I'm trying to change. I originally was adding the image to this.target but I'd like to add it to the _playbtn MovieClip I created in the code.

I worked out that I can assign a name to the new object and call on it with
his.target.getChildByName('newobjectsname');
I'm sure this is the worst way to do it and there's a better way to make a functional button using just .as and .png files but I can't find any documentation. If you have any tutorials to suggest it would be appreciated. I'm sure my solution is misguided and just plain retarded but I can't find any other way to do this without adding items to the library.