teddy Posted December 7, 2011 Share Posted December 7, 2011 Hi, I keep getting this message and can not figure out why. The greensock folder is in the com directory and there is no issue there. Here is the error msg: ----------------------------------------------------------------- Error: Cannot tween a null object. at com.greensock::TweenLite()[C] at com.greensock::TweenMax()[C] at com.greensock::TweenMax$/to()[C] at ShapefileExample/mapOver()[C] TypeError: Error #1009: Cannot access a property or method of a null object reference. at com.greensock::TweenLite/init()[C] at com.greensock::TweenMax/init()[C] at com.greensock::TweenMax/renderTime()[C] at com.greensock.core::SimpleTimeline/renderTime()[C] at com.greensock::TweenLite$/updateAll()[C] --------------------------------------------------------------------------------- Here is my code: package { import com.greensock.*; import com.cartogrammar.shp.ShpMap; import com.cartogrammar.shp.ShpFeature; import flash.events.Event; import flash.display.Sprite; import flash.display.MovieClip; import flash.events.MouseEvent; import flash.geom.ColorTransform; [sWF(width='800', height='800', backgroundColor='#ffffff', frameRate='30')] /** * An example of drawing a simple map from a shapefile using my ShpMap class and Edwin van Rijkom's library. * * @author Andy Woodruff (cartogrammar.com/blog) * */ public class ShapefileExample extends Sprite { private var map : ShpMap; public function ShapefileExample() { map = new ShpMap("data/Zones.shp","data/Zones.dbf");//Original map.buttonMode=true; map.addEventListener(MouseEvent.MOUSE_OVER, mapOver); map.addEventListener(MouseEvent.MOUSE_OUT, mapOut); //addChild(road); addChild(map); map.addEventListener("map loaded",onMapLoaded); } // Need to wait for the map to finish loading/drawing before it can be resized correctly. private function onMapLoaded(event:Event):void { map.scaleX = map.scaleY = map.width > map.height ? stage.stageWidth/map.width : stage.stageHeight/map.height; // just for fun, add a marker to somewhere around my house! //addMarkerAt( 9,38 ); } function mapOver(e:MouseEvent):void{ var mapItem:MovieClip = e.target as MovieClip; TweenMax.to(mapItem, .5, {tint:0xFF9900}); } function mapOut(e:MouseEvent):void{ var mapItem:MovieClip = e.target as MovieClip; trace(mapItem); TweenMax.to(mapItem, .5, {removeTint:true}); } } Link to comment Share on other sites More sharing options...
GreenSock Posted December 7, 2011 Share Posted December 7, 2011 That just means that you're tweening a null object and judging by your code, it must mean that ShpMap doesn't extend MovieClip. Here's your problem: var mapItem:MovieClip = e.target as MovieClip; If e.target isn't a MovieClip, that expression will evaluate to null. To prove it, just add this right above that line: trace((e.target is MovieClip)); //I bet it traces false Why are you casting to a MovieClip anyway? I don't see any benefit. Link to comment Share on other sites More sharing options...
teddy Posted December 7, 2011 Author Share Posted December 7, 2011 You are right it is false. What I want to do is: I want to show the name of the states when I mouseover the shapefile. Isn't movie clip the only way to do it? I am following the snorkl exampe via thanks. Link to comment Share on other sites More sharing options...
Carl Posted December 7, 2011 Share Posted December 7, 2011 hmmm. If you are using a 3rd party class to create your mapItems, you will have to use whatever object type that class is creating. It appears they are not using MovieClips. you could probably try not casting the mapItem at all: var mapItem:MovieClip = e.target or to find out what mapItem is trace("e.target is a " + e.target) and use whatever object type that tells you. it could be a ShpFeature. don't know. Link to comment Share on other sites More sharing options...
teddy Posted December 8, 2011 Author Share Posted December 8, 2011 carl, var mapItem:MovieClip = e.target did not work and mapItem is a sprite. I can't figure out how I would use a sprite in this case to have the same outcome as snorkl's youtube example????? thanks. Link to comment Share on other sites More sharing options...
Carl Posted December 8, 2011 Share Posted December 8, 2011 first I'm pretty sure this: http://www.snorkl.tv/2010/11/part-1-bui ... flash-as3/ is the tutorial you are referencing. (just so others have an idea). did you try using var mapItem:Sprite = e.target as Sprite() technically you can get rid of that line all together and just use TweenMax.to(e.target, .5, {tint:0xFF9900}); I really don't know anything thing about the map shapes (external class) you are using but a Sprite should have no problem changing it's color with TweenMax when you roll over it. Link to comment Share on other sites More sharing options...
teddy Posted December 8, 2011 Author Share Posted December 8, 2011 Carl, I love you man. I can't tell you how much work you saved me. Basically I was in the process of drawing over 600 counties,states, cities and int'l border. Now thanks to the shpfeature.as and your excellent tutorial and greensock, only 4 lines of code is all that is needed. Thank you very much. this works below..... function mapOver(e:MouseEvent):void{ TweenMax.to(e.target, .5, {tint:0xFF9900}); } function mapOut(e:MouseEvent):void{ TweenMax.to(e.target, .5, {removeTint:true}); } Link to comment Share on other sites More sharing options...
Carl Posted December 9, 2011 Share Posted December 9, 2011 you're welcome. glad to hear that you didn't have to do a bunch of stuff 600 times. ouch. c Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now