Flash_and_Flex_03_2009

ActionScript Development

Listing 3b. Continuing CustomMarker Component code

// setting line style tmpSprite.graphics.lineStyle(2,0xFFFFFF); // setting fill tmpSprite.graphics.beginFill(_markerColor,0.6); // drawing the shape

_urlText.addEventListener(TextEvent.LINK, goToMarkerURL);

_urlText.addEventListener(MouseEvent.MOUSE_OVER, handleLinkOver); _urlText.addEventListener(MouseEvent.MOUSE_OUT, handleLinkOut); heightH += Math.round(_urlText.textHeight); } else { heightH += 7; } // setting position based on the above calculations _titleText.x = Math.round(-widthW / 2 – padding); _titleText.y = Math.round(-heightH – padding / 1.5); _addressText.x = _titleText.x; _addressText.y = _titleText.y + _ titleText.textHeight; // draw custom marker shape _customBigMarkerShape = new Sprite(); // create the bubble _customBigMarkerShape = createBubble(widthW, heightH, padding, radius); // add bubble object addChild(_customBigMarkerShape); // method to create the bubble object private function createBubble(w:uint = 20, h:uint = 20, padding:uint = 1, radius:uint = 4): Sprite { var tmpSprite:Sprite = new Sprite(); // shape coords var tipShape:Array; tipShape = [ [0, 0], [7, -7], [w / 2, -7], [w / 2 + radius + padding, -7, w / 2 + radius + padding, -7 – radius], [w / 2 + radius + padding, -h], [w / 2 + padding + radius, -radius-h, w / 2, -radius-h], [-w / 2 – padding , -radius-h], [-w / 2 -padding -radius, -radius-h, -w / 2 -padding -radius, -h], [-w/2 -padding -radius, -7-radius], [-w / 2 – padding -radius, -7, -w /2 – padding, -7], [-7, -7], [0,0]]; // add object _customBigMarkerShape.addChild(_titleText); _customBigMarkerShape.addChild(_addressText); if (_web && _web.length > 0){ _customBigMarkerShape.addChild(_urlText); } }

var len:uint = tipShape.length; for ( var i:int = 0; i < len; i++) { if (i == 0) {

// if is the first entry we move to that point tmpSprite.graphics.moveTo(tipShape[i][0], tipShape[i][1]); } else if (tipShape[i].length == 2) { // if there are 2 coords for this entry // we draw a line tmpSprite.graphics.lineTo(tipShape[i][0], tipShape[i][1]); } else if (tipShape[i].length == 4) { // if there are 4 coords we draw a curve tmpSprite.graphics.curveTo(tipShape[i][0], tipShape[i][1], tipShape[i][2], tipShape[i][3]); } } // mouse over for website link private function handleLinkOver(event:MouseEvent):void { _urlFormat.underline = true ; _urlText.setTextFormat(_urlFormat); } // mouse out for website link private function handleLinkOut(event:MouseEvent):void { _urlFormat.underline = false ; _urlText.setTextFormat(_urlFormat); } // go to the website link private function goToMarkerURL(event:TextEvent):void { var urlRequest:URLRequest = new URLRequest(event.text); navigateToURL(urlRequest, "_blank"); } tmpSprite.graphics.endFill(); // setting drop shadow filter tmpSprite.filters = [_dropShadow]; tmpSprite.useHandCursor = false ; return tmpSprite; }

}

}

03/2009 (5)

50

Made with FlippingBook HTML5