View(LzView)

出自OpenFace

跳转到: 导航, 搜索

目录

<view>

The most basic viewable element.

JavaScript: LzView


Extends Node The <view> is the most basic viewable element in an OpenLaszlo application. Anything that is displayed on the canvas is a view or extends the view class. A view is a rectangle, which can be visible or invisible, and which can contain other views or display "resources" such as images, or other supported media. One view controls one displayable resource. The view system is strictly hierarchical; that is, each view has a single parent but can have multiple children.

The following code shows one view nested inside another:


<canvas height="100" width="100">
 <view width="50" height="50" bgcolor="red">
   <view width="30" height="30" bgcolor="blue"/>
 </view> 
</canvas>


LzView extends LzNode, which is the fundamental abstract class of LZX.

For more a gentle introduction to views please see the Laszlo tutorials, particularly Laszlo Basics and Understanding Views. For a more rigorous explanation of views see theDeveloper's Guide, particularly the views chapter.

Attributes

Name    Usage    Type(Tag)    Type(JS)    Default    Category

cloneManager  JS only    LzNode                          readonly

        If this node is replicated due to data replication, the LzReplicationManager which controls this node.


datapath    Tag & JS    string    LzDatapath                readonly

        A pointer to the LzDatapath attached to this node, if there is one.


align     Tag only left | center | right left              final


bgcolor     Tag & JS color   Number                  setter

       The color of background of this view. Null if there is no bgcolor. A number from 0 - 0xFFFFFF.


clip        Tag only       boolean     Boolean     false    final

       If true, the resource and children of this view are masked to its width and height.


fgcolor   Tag & JS color    Number                  setter

      A color to use to render object that appears inside this view, which includes any vector or bitmap art in the view's resource and any contained views.



focusable  Tag & JS boolean   Boolean                 readonly

      If true, this view will participate in keyboard focus and will receive focus events and keyboard events when it has the focus. (see LzFocus for more details)


fontsize   Tag & JS size    Number                    setter

       Pixel size to use to render text which appears inside this view. The default is 8.



frame    Tag & JS number    Number              0      setter

      See also the resource attribute. Setting this attribute will change the frame that is being displayed by the resource associated with this view. The first frame of the resource is frame 0. Setting a view's 'donttrackplay' option to true will allow the view's resource to play without updating the value of the view's frame property. This can save CPU usage in cases where the application doesn't need to know what frame the resource is showing while it is playing. Removed "at" sign from the line below so that this field does not appear in the documentation. field selected: Setting this attribute calls the abstract method setSelected. See LzSelectionManager.


height   Tag & JS size   Number                      setter

    The height of the view


onblur    Tag only     script  eventhandler

     The onblur script is executed when an element loses focus either by the pointing device or by tabbing navigation.



ondata     Tag & JS    script    LzDelegate           setter

     The ondata script is executed when the data selected by a view's datapath changes.



onfocus    Tag only    script eventhandler

     The onfocus script is executed when an element receives focus either by the pointing device or by tabbing navigation.



onkeydown  Tag & JS     script   LzDelegate              setter

     The onkeydown script is executed when this view has the focus and a key is pressed down. Multiple key down events are sent for a key that is held down. This event is sent with the keycode for the key that is down.



opacity     Tag & JS    opacity     Number      1.0       setter

      The opacity value for the view, a number between 0 and 1


resource   Tag & JS     string      String             setter

      The name of this view's resource, or the URL the resource was loaded from.


source     JS only                             setter

       The URL from which to load the resource for this view. If this attribute is set, the media for the view is loaded at runtime.


stretches    Tag & JS      width | height | both    any      setter

       Setting stretches causes a view to change its coordinate space so that everything it contains (resources and other views) fit exactly into the view's width and/or height. The default for this property is "none". This is used to resize a view's contents by setting its width and/or height.


totalframes   JS only    Number                     readonly

       The total number of frames for this view's resource.


visible   Tag & JS    boolean    Boolean    true           setter

      A value of true means that this view is shown. A value of false means that this view is hidden. Setting this attribute to null means that the runtime will hide this view when: its opacity is 0, it has a datapath that does not match a node, or it is loading its media. In this case, the the value of the visible member of the view will reflect the view's current visible state. This is the default behavior for this attribute. Note that an otherwise clickable view that is not visible will have no click region will not be clickable. Also be aware that in Javascript, the && operator does not coerce values to booleans. For instance, given an expression like this: visible="a && b", if a is null, the value returned by the constraint expression will be null -- not false.


width   Tag & JS     size     Number               setter     The width of the view


x     Tag & JS     number    Number     0           setter     The x position of the view


y     Tag & JS      number    Number      0         setter

    The y position for the view


Attributes inherited from Node

id, name, parent, subnodes


Methods

destroy()

LzView.destroy()

destroy the view itself.


getAbsoluteX()

LzView.getAbsoluteX()

Gets the x position of the view relative to (0,0) point of the screen.


getAbsoluteY()

LzView.getAbsoluteY()

Gets the y position of the view relative to (0,0) point of the screen.


getTotalFrames()

LzView.getTotalFrames()

Gets the total frame count of the resource that the view uses


getBGColor()

LzView.getBGColor() Gets the background color of the view . Returns A color in rgb format; for example, 0xff0000 is red.



getColor()

LzView.getColor() Gets the color of the view (the view's resource and any subviews) view as as set with setColor(). Returns A color in rgb format; for example, 0xff0000 is red.



getHeight()

LzView.getHeight() Returns the height of the view.


getResource()

LzView.getResource()

Returns the name of the resource that the view uses.



getRotation()

LzView.getRotation()

Returns the rotation(in degree) of the view.


getSource()

LzView.getSource()

Returns the url of the background image of the view.


getWidth()

LzView.getWidth() Returns the width of the view.



getX()

LzView.getX()

Returns the x position of the view.



getY()

LzView.getY()

Returns the y position of the view.



init()

LzView.init() Called right before the view is shown. See LzNode.init for more.



sendBehind()

LzView.sendBehind(v) Puts this view behind one of its siblings.

Parameters Name Type Desc v LzView The view this view should go in front of. If the passed view is null or not a sibling, the method has no effect. Returns Type Desc Boolean Method returns true if the operation is successful.



sendInFrontOf()

LzView.sendInFrontOf(v) Puts this view in front of one of its siblings.

Parameters Name Type Desc v LzView The view this view should go in front of. If the passed view is null or not a sibling, the method has no effect. Returns Type Desc Boolean Method returns true if the operation is successful.


setAlign()

LzView.setAlign(align) Sets the alignment for the view to the given value. The alignment is based on the size of this view as compared to the size of the view's immediate parenbgRef.

Parameters Name Type Desc align String The alignment for the view. This is one of "left", "center", and "right"


setBGColor()

LzView.setBGColor(bgc) Gives the view a bgcolor that is the same size as the view.

Parameters Name Type Desc bgc Integer The 0-FFFFFF number to be used for the new background color.


setColor()

LzView.setColor(c) Sets the color of the view (the view's resource and any subviews) to the the color given. This will completely override any color information in the view or subview resources. Use the view method setColorTransform to tint a view.

Parameters Name Type Desc c Integer A color in rgb format; for example, 0xff0000 is red.


setHeight()

LzView.setHeight(v) Sets the height of the view the given value. If the view is set to stretch its resource, the resource will be resized to the new value. If the value 'null' is given for the new height, then the height is unset, and the height of the view will be the size measured of its contents.

Parameters Name Type Desc v Number The new value for the height


setOpacity()

LzView.setOpacity(v) Sets the opacity for the view. The opacity is a number between 0.0 (transparent) and 1.0 (opaque).

Parameters Name Type Desc v Number The new value for the opacity


setResource()

LzView.setResource(resourceName) This method associates a view with a named library element. If the view's isVisible property is true, the resource will be displayed when it is attached

Parameters Name Type Desc resourceName String a string naming the id of the resource to attach



setResourceNumber()

LzView.setResourceNumber(n) For resources which have more than one frame, this function sets the view to display the numbered resource. For Flash assets, resource numbers correspond to movieclip frames.

Parameters Name Type Desc n Integer the number of the resource to show



setRotation()

LzView.setRotation(v) Sets the rotation for the view to the given value.

Parameters Name Type Desc v Number The new value for rotation.


setSource()

LzView.setSource(source, cache, headers) This function allows the view to load its media from an URL at runtime. Resources loaded with setSource will replace compiled resources when the request is made.

Parameters Name Type Desc source String The URL from which to load the resource for this view. cache String If set, controls caching behavior. Choices are none , clientonly , serveronly , both (the default). headers String Headers to send with the request, if any.



setValign()

LzView.setValign(valign) Sets the vertical alignment for the view to the given value. The alignment is based on the height of this view as compared to the height of the view's immediateparent.

Parameters Name Type Desc valign String The vertical alignment for the view. This is one of "top", "middle", and "bottom"



setVisible()

LzView.setVisible(amVisible) This method sets the visible attribute of the view and also disables or re-enables any click region associated with the view. Note that a value of null is different from a value of false for this attribute. See the description of the visible attribute for details.

Parameters Name Type Desc amVisible Boolean boolean for visibility of view


setWidth()

LzView.setWidth(v) Sets the width of the view. If the view is set to stretch its resource, the resource will be resized to the new value. If the value 'null' is given for the new width, then the width is unset, and the width of the view will be the size of its contents.

Parameters Name Type Desc v Number The new value for the width



setX()

LzView.setX(v) Sets the x position of the view to the given value.

Parameters Name Type Desc v Number The new value for x.



setY()

LzView.setY(v) Sets the y position for the view to the given value.

Parameters Name Type Desc v Number The new value for y.


stretchResource()

LzView.stretchResource(xory) Sets the view so that it stretches its resource in the given axis so that the resource is the same size as the view. The has the effect of distorting the coordinate system for all children of this view, so use this method with care.

Parameters Name Type Desc xory String If this is defined, set the resource to stretch only in the given axis ("width" or "height"). Otherwise set the resource to stretch in both axes.


Methods inherited from LzNode

getAttribute, setAttribute,applyConstraint



Events

onenabled,onerror, onfocus, onwidth, onheight, onopacity, onvisible, onwidth, onx, ony, onpathready, oncloneend, onclonenumber

Events inherited from LzNode

ondata, oninit