View Full Version : [as3] Thumbnail extends Sprite
lowdown
February 5th, 2007, 10:51 PM
So I have a class that extends sprite. When I call an instance of my thumbnail object, I apparently can't use typical transforms on it by accessing .x and .y properties. These are not inherited from the superclass? Do I need to tell it to inherit these traits?
TheCanadian
February 5th, 2007, 11:08 PM
All properties are inherited from the super class.
lowdown
February 5th, 2007, 11:16 PM
All properties are inherited from the super class.
then why can't I move it when I make var c:Thumbnail = new Thumbnail() but if I make a new Sprite I can? Is there some syntax I am missing?
Currently I am creating a sprite and putting my thumbnail object in the sprite so I can move it about the x and y. I had hoped that since I extended sprite I would have access to that functionality without adding another layer (at this point many many layers) of objects to my hierarchy :<
TheCanadian
February 5th, 2007, 11:21 PM
then why can't I move it when I make var c:Thumbnail = new Thumbnail() but if I make a new Sprite I can? Is there some syntax I am missing?
Currently I am creating a sprite and putting my thumbnail object in the sprite so I can move it about the x and y. I had hoped that since I extended sprite I would have access to that functionality without adding another layer (at this point many many layers) of objects to my hierarchy :<
So you use c.x and c.y to access the properties? Maybe post some more code.
lowdown
February 5th, 2007, 11:34 PM
So you use c.x and c.y to access the properties? Maybe post some more code.
That is what I was trying to do without success...
Here is a bit of the thumbnail:
public class LocationThumbnail extends Sprite
{
private var _area:Array;
private var _areaIndex:Number
private var _locationIndex:Number;
private var _container:Sprite;
private var _numImages:Number;
private var _slideContainer:Sprite;
private var isOn:Boolean;
private static const PATH_TO_IMAGES:String = new String("images/plane/");
private static const PATH_TO_THUMBS:String = new String("images/plane/thumbs/");
private var thumbContainer:Sprite = new Sprite();
public function LocationThumbnail(area:Array, container:Sprite, areaIndex:Number, locationIndex:Number, numImages:Number, slideContainer:Sprite)
{
_area = area;
_areaIndex = areaIndex;
_locationIndex = locationIndex;
_container = container;
_numImages = numImages;
_slideContainer = slideContainer;
thumbContainer.name = "thumbContainer";
isOn = false;
create();
}
private function create():void {
//load the image register a listener and name the thumbnail
var thumbImage:BitmapLoader = new BitmapLoader(PATH_TO_THUMBS + _area[_areaIndex].location[_locationIndex].image, thumbContainer);
thumbImage.addEventListener(Event.COMPLETE, addOverlay);
thumbContainer.name = _locationIndex.toString();
//position the thumbnail in rows of 5
thumbContainer.x = (75 * (_locationIndex % 5)) + 27.5;
thumbContainer.y = (75 * Math.floor(_locationIndex / 5) + 20) + 245;
//make a button
thumbContainer.buttonMode = true;
//add it to the display list
_container.addChild(thumbContainer);
//events
thumbContainer.addEventListener(MouseEvent.MOUSE_O VER, thumbOver);
thumbContainer.addEventListener(MouseEvent.MOUSE_O UT, thumbOut);
thumbContainer.addEventListener(MouseEvent.CLICK, thumbClick);
thumbContainer.addEventListener(Event.REMOVED_FROM _STAGE, destroy);
}
and here is a bit of where I am calling it and can't make it move by calling the x and y properties:
private function markerClick(evt:MouseEvent):void {
evt.currentTarget.getChildByName("visited").alpha = .95;
var cm:Number = evt.currentTarget.name;
while (_slideContainer.numChildren > 0) {
_slideContainer.removeChildAt(0);
}
var slide:Slide = new Slide(_area, _slideContainer, cm, 0);
var cl:Number = 0;
var thumbContainer:Sprite = new Sprite();
_area[evt.target.name].location[0].isOn = true;
thumbContainer.name = "thumbcontainer";
for (var loc:Object in _area[cm].location) {
var thumb:LocationThumbnail = new LocationThumbnail(_area,
thumbContainer,
cm, cl,
_area[cm].location.length,_slideContainer);
thumb.x = 356;
thumbContainer.addChild(thumb);
cl++;
}
_slideContainer.addChild(thumbContainer);
_area[evt.target.name].isOn = true;
}
You can see where I try and push the thumb, but it doesn't work. Is it because of my convoluted container scheme? I guess so because I just did a simple test and it works just fine. I pass containers because I wasn't sure how to get them to display right if I didn't. This must be bad form, eh?
Thanks for the input. It is appreciated.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.