`
zyjwy02
  • 浏览: 139182 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Using error tips

    博客分类:
  • Flex
阅读更多

Using error tips

Error tips are instances of the ToolTip class that get their styles from the errorTip class selector. They are most often seen when the Flex validation mechanism displays a warning when data is invalid. But you can use the definitions of the errorTip style and apply it to ToolTips to create a custom validation warning mechanism.

The styles of an error tip are defined in the defaults.css file, which is in the framework.swc file. It specifies the following default settings for errorTip (notice the period preceding errorTip, which indicates that it is a class selector):

.errorTip {
    color: #FFFFFF;
    fontSize: 9;
    fontWeight: "bold";
    shadowColor: #000000;
    borderColor: #CE2929;
    borderStyle: "errorTipRight";
    paddingBottom: 4;
    paddingLeft: 4;
    paddingRight: 4;
    paddingTop: 4;
}

You can customize the appearance of error tips by creating a new theme that overrides these styles, or by overriding the style properties in your application. For more information on creating themes, see About themes.

You can create ToolTips that look like validation error tips by applying the errorTip style to the ToolTip. The following example does not contain any validation logic, but shows you how to use the errorTip style to create ToolTips that look like validation error tips. When you run the example, press the Enter key after entering text into the TextInput controls.

<?xml version="1.0"?>
<!-- tooltips/ErrorTipStyle.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" verticalGap="20">
  <mx:Script><![CDATA[
     import mx.controls.ToolTip;
     import mx.managers.ToolTipManager;
     
     private var errorTip:ToolTip;
     private var myError:String;
  
     private function validateEntry(type:String, event:Object):void {
        // NOTE: Validation logic would go here.
        switch(type) {
           case "ssn":
            myError="Use SSN format (NNN-NN-NNNN)";
            break;
           case "phone":
            myError="Use phone format (NNN-NNN-NNNN)";
            break;
        }
        // Use the target's x and y positions to set position of error tip.
        errorTip = ToolTipManager.createToolTip(myError,event.currentTarget.x + event.currentTarget.width,event.currentTarget.y) as ToolTip;
     
        // Apply the errorTip class selector.
        errorTip.setStyle("styleName", "errorTip");
     }
  ]]></mx:Script>

  <mx:TextInput id="ssn" enter="validateEntry('ssn',event)"/>
  <mx:TextInput id="phone" enter="validateEntry('phone',event)"/>
</mx:Application>

Another way to use error tips is to set the value of the errorString property of the component. This causes the ToolTipManager to create an instance of a ToolTip and apply the errorTip style to that ToolTip without requiring any coding on your part.

The following example shows how to set the value of the errorString property to create an error tip:

<?xml version="1.0"?>
<!-- tooltips/ErrorString.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" verticalGap="20">
  <mx:Script><![CDATA[
     import mx.controls.ToolTip;
     import mx.managers.ToolTipManager;
     
     private var errorTip:ToolTip;
     private var myError:String;
  
     private function validateEntry(type:String, event:Object):void {
        // NOTE: Validation logic would go here.
        switch(type) {
           case "ssn":
            myError="Use SSN format";
            break;
           case "phone":
            myError="Use phone format";
            break;
        }

        event.currentTarget.errorString = myError;

     }
  ]]></mx:Script>

  <mx:TextInput id="ssn" enter="validateEntry('ssn',event)"/>
  <mx:TextInput id="phone" enter="validateEntry('phone',event)"/>
</mx:Application>

You can also specify that the ToolTipManager creates an error tip when you call the createToolTip() method by specifying the value of the errorTipBorderStyle property, as the following example shows:

<?xml version="1.0"?>
<!-- tooltips/CreatingErrorTips.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script><![CDATA[
  import mx.managers.ToolTipManager;
  import mx.core.IToolTip;

  public var myTip:IToolTip;

  private function createBigTip(event:Event):void {
     var myError:String = "These buttons let you save, exit, or continue with the current operation."
     myTip = ToolTipManager.createToolTip(myError, event.currentTarget.x + event.currentTarget.width, event.currentTarget.y, "errorTipRight");
  }

  private function destroyBigTip():void {
     ToolTipManager.destroyToolTip(myTip);
  }
  
  ]]></mx:Script>
  <mx:Panel rollOver="createBigTip(event)" rollOut="destroyBigTip()">
     <mx:Button label="OK" toolTip="Save your changes and exit."/>
     <mx:Button label="Apply" toolTip="Apply changes and continue."/>
     <mx:Button label="Cancel" toolTip="Cancel and exit."/>
  </mx:Panel>
</mx:Application>
分享到:
评论

相关推荐

    Tips and tricks using the preprocessor 2

    This is the second article in a two-piece series covering the preprocessor. In the previous article we covered the basics—object- and function...ended with the two special directives #error and #pragma.

    AT&T Assembly Language

    Open error return codes 459 Closing files 460 Writing to Files 460 A simple write example 460 Changing file access modes 462 Handling file errors 462 Reading Files 463 A simple read example 464 A more...

    Django 1.1 Testing and Debugging.pdf

    Tips on asking questions that will get good answers 370 Opening a new ticket to report a problem 372 Summary 374 Chapter 11: When it's Time to Go Live: Moving to Production 375 Developing an ...

    TclTk 8.5 Programming Cookbook.pdf

    From the basics to creating applications, it’s full of indispensable tips and tricks to make the most of the language. Overview The quickest way to solve your problems with Tcl/Tk 8. Understand the ...

    JDBC Developers Guide Reference.rar

    Document Structure The Oracle JDBC Developers Guide and Reference contains 21 chapters and one appendix: Chapter 1, "Overview" This chapter provides an overview of the ...corresponding ORA error numbers.

    Frontend Architecture for Design Systems

    Using real-world examples, case studies, and practical tips and tricks throughout, author Micah Godbolt introduces you to the four pillars of frontend architecture. He also provides compelling ...

    [machine_learning_mastery系列]better_deep_learning

    Nevertheless, neural networks have been used in academia and industry for decades now and there are a suite of standard techniques, tips, and configurations that you can use to greatly increase the ...

    Beginning Python (2005).pdf

    Using Python to Transform XML Using XSLT 294 Try It Out: Transforming XML with XSLT 294 Putting It All Together: Working with RSS 296 RSS Overview and Vocabulary 296 Making Sense of It All 296 ...

    Debugging ASP.NET

    Tips for Using Trace Information Summary 7. Visual Studio .NET Debugging Environment Introduction to Features Attaching to Processes Setting It All Up Inline Debugging of ASP.NET Pages ...

    WordPress 2.7 Cookbook.pdf

    Tips and things to know about fonts 47 Creating and integrating a favicon 48 Getting ready 48 Favicon format 48 How to do it 48 How it works 49 Integrating your own logo 49 Getting ready 50 ...

    bochs user manual 单html文件+pdf 英文原版

    4.3.26. debug/info/error/panic 4.3.27. debugger_log 4.3.28. com[1-4] 4.3.29. parport[1-2] 4.3.30. sound 4.3.31. speaker 4.3.32. sb16 4.3.33. es1370 4.3.34. ne2k 4.3.35. pcipnic 4.3.36. e1000 4.3.37. ...

    Common OpenStack Deployments pdf

    Throughout, you’ll find up-to-the minute coverage of enhancements that make the OpenStack platform more mature and production ready, plus expert tips on debugging and growth. The authors ...

    USB Complete 3rdEdition

    Tips for Using INF Files 277 What the User Sees 279 10. Detecting Devices 281 A Brief Guide to Calling API Functions 281 Managed and Unmanaged Code 282 Documentation 284 Using Visual C++ .NET 284 ...

    Oracle APEX Cookbook, 2nd Edition

    Make the development process easier by enhancing error handling Developing HTML5 and CSS3 supported web applications Follow hands on examples to make the most out of the possibilities that APEX has to...

    Access 2007 Programming

    Chapter 4: Debugging, Error Handling, and Coding Practices . . . . . . . . . . . . 105 Part II: Data Manipulation 145 Chapter 5: Parsing Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

    building restful web services with spring 5 2e

    Devise response formats and error handling strategies, offering a consistent and flexible structure to simplify integration for service consumers Follow the best approaches for dealing with a service...

    Learning Node.js Development-Packt Publishing(2018).epub

    I always recommend using Atom, which you can find at atom.io. It's free, open-source, and it's available for all operating systems, namely Linux, macOS, and Windows. It's created by the folks behind ...

    最完整的Toad For Oracle使用手册

    Viewing Source Surrounding a PL/SQL Error 863 Dataset Operations 864 Data Grids 866 DBMS Output 881 Finding Data 883 Generate Test Data 890 Working with Database Objects 896 Schema Browser Overview ...

    Troubleshooting.Xcode.14842156

    Troubleshooting Xcode is a handbook for software developers of all levels creating applications for iOS and OS X using both Objective-C and Swift. If you’ve struggled in the... Power tips: Beyond Xcode

    GTK+ 1.2 Tutorial

    25. Tips For Writing GTK Applications 26. Contributing 27. Credits 28. Tutorial Copyright and Permissions Notice A. GTK Signals GtkObject GtkWidget GtkData GtkContainer GtkCalendar GtkEditable ...

Global site tag (gtag.js) - Google Analytics