Use MX. Skins. programmaticskin to implement custom components (reuse of custom components)

Source: Internet
Author: User

MX. Skins. programmaticskin is the base class of the appearance element. They draw themselves through programming.

The following describes the class by implementing a custom tooltip.

Tooltipborderskin.

Package skins
{
Import flash. display. graphics;
Import flash. Geom. Point;
 
Import MX. Skins. programmaticskin;
Import flash. Filters. bitmapfilter;
Import flash. Filters. bitmapfilterquality;
Import flash. Filters. dropshadowfilter;

Public class tooltipborderskin extends programmaticskin
{
Public Function tooltipborderskin ()
{
Super ();
}

Override protected function updatedisplaylist (unscaledwidth: Number,
Unscaledheight: Number): void {
Trace ("W =" + unscaledwidth );
Trace ("H =" + unscaledheight );
VaR G: Graphics = graphics;
G. Clear ();
// G. linestyle (0, 0xff0000 );
G. beginfill (0xff0000, 0.5 );
// G. drawrect (0, 0, unscaledwidth, unscaledheight );
G. drawroundrect (0, 0, unscaledwidth, unscaledheight, 15, 10 );
G. endfill ();
VaR _ w: Number = unscaledwidth;
VaR _ H: Number = unscaledheight;
VaR point1: Point = new point (_ w/3, _ H );
VaR point2: Point = new point (2 * _ w/3, _ H );
VaR point3: Point = new point (0, 2 * _ H );
G. beginfill (0xff0000, 0.5 );
G. moveTo (point1.x, point1.y );
G. lineto (point3.x, point3.y );
G. lineto (point2.x, point2.y );
G. endfill ();

This. Filters = [getdropshadowfilter ()];
}

// Add a shadow
Private function getdropshadowfilter (): bitmapfilter {
VaR color: Number = 0x000000;
VaR angle: Number = 45;
Varalpha: Number = 0.8;
VaR blurx: Number = 8;
VaR blury: Number = 8;
VaR distance: Number = 15;
VaR strength: Number = 0.65;
VaR inner: Boolean = false;
VaR knockout: Boolean = false;
VaR quality: Number = bitmapfilterquality. High;


Return new dropshadowfilter (distance,
Angle,
Color,
Alpha,
Blurx,
Blury,
Strength,
Quality );
}
}
}

 

 

We can call the above method in the following custom style.

<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" creationcomplete = "initapp ()">
 
<Mx: style>

Tooltip
{
Borderstyle: inset;
Color: # ffffff;
Borderskin: classreference ("skins. tooltipborderskin ");
}
</MX: style>
 
<Mx: SCRIPT>
<! [CDATA [
Import MX. Events. tooltipevent;
Import MX. Managers. tooltipmanager;

Private function initapp (): void {
B5.addeventlistener (tooltipevent. tool_tip_show, mov?ltip );
}
Private function movetooltip (Event: tooltipevent): void {
Trace (event );
Event. tooltip. x = b5.x + 5;
Event. tooltip. Y = b5.y-35;
}

]>
</MX: SCRIPT>
<Mx: button id = "B5" width = "30" tooltip = "This is good! "Height =" 20 "x =" 226 "Y =" 167 "/>

</MX: Application>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.