`
zyjwy02
  • 浏览: 141187 次
  • 性别: 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 1

    - **`#error`**:当预处理器遇到`#error`指令时,会立即终止编译并显示一个错误消息。这对于确保某些条件得到满足是非常有用的。 示例: ```c #ifndef MY_APP_VERSION #error "MY_APP_VERSION must be defined!...

    Tips and tricks using the preprocessor 2

    在前一篇文章中,我们已经介绍了预处理器的基础知识:对象宏、函数宏、`#include`指令、条件编译以及两个特殊的指令`#error`和`#pragma`。在这篇文章里,我们将进一步探讨一些高级的预处理器主题。 #### 函数宏的...

    Swift-开发者必备Tips

    ### Swift 开发者必备 Tips #### 单例 (Singleton) 单例模式是一种常见的设计模式,用于确保一个类只有一个实例,并提供一个全局访问点。在 Swift 中实现单例通常包括私有初始化方法和一个静态常量来存储单例实例...

    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 ...

    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 ...

    Go in Practice.pdf

    - Tips for improving test coverage and maintaining test suites over time. Effective testing and debugging strategies are essential for ensuring the quality and maintainability of Go applications. ###...

    [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 ...

    Oracle Database 10g PL-SQL Programming

    - **JDeveloper**: An integrated development environment (IDE) provided by Oracle for building applications using Java and PL/SQL. This includes creating, editing, testing, and debugging PL/SQL code. ...

    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 ...

Global site tag (gtag.js) - Google Analytics