⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fsdefinebutton.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * FSDefineButton.java
 * Transform
 * 
 * Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution.
 *  * Neither the name of Flagstone Software Ltd. nor the names of its contributors 
 *    may be used to endorse or promote products derived from this software 
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.flagstone.transform;

import java.util.*;

/**
FSDefineButton defines the appearance of a button and the actions performed when the 
button is clicked.
 
<table class="datasheet">

<tr><th align="left" colspan="2">Attributes</th></tr>

<tr>
<td><a name="FSAction_0">type</a></td>
<td>Identifies the action when it is encoded. Read-only.</td>
</tr>
<tr>
<td><a name="FSDefineButton_1">identifier</a></td>
<td>An unique identifier for this object, in the range 1..65535.</td>
</tr>

<tr>
<td><a name="FSDefineButton_2">buttonRecords</a></td>
<td>an array of FSButton objects that define the appearance of the button in each of its states. The array must contain at least one FSButton object.</td>
</tr>

<tr>
<td><a name="FSDefineButton_3">actions</a></td>
<td>an array of action objects that are executed when the button is clicked.</td>
</tr>

<tr><td><a name="FSDefineButton_4">encodedActions</a></td>
<td>An array of bytes containing encoded actions can also be set. The encoded actions are typically generated by the parser in the Translate framework. The actions array and encodedActions cannot both be valid at the same time. Accessor methods used to set either of the attributes will set the other to null.</td>
</tr>

</table>

<p>A FSDefineButton object must contain at least one FSButton object. If more than one button record is defined for a given button state then each shape will be displayed by the button. The order in which the shapes are displayed is determined by the layer assigned to each FSButton object.</P>

<h1 class="datasheet">Examples</h1>

<p>1. Define a simple button that highlights itself when the mouse is move over it. No actions are performed when the button is clicked.</p>

<pre>
FSDefineShape normal = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, shape);
FSDefineShape highlight = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, highlightShape);

ArrayList records = new ArrayList();
ArrayList actions = new ArrayList();

records.add(new FSButton(FSButton.Up, normal.getIdentifier(), 1));
records.add(new FSButton(FSButton.Over, highlight.getIdentifier(), 2));

FSDefineButton button = new FSDefineButton(movie.newIdentifier(), records, actions);
</pre>

<p>2. Define a "complex" button that highlights itself when the mouse is move over it and actions are executed when the button is clicked.</p>

<pre>
FSDefineShape upShape = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, shape1);
FSDefineShape overShape = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, shape2);
FSDefineShape downShape = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, shape3);

ArrayList records = new ArrayList();
records.add(new FSButton(FSButton.Up, upShape.getIdentifier(), 1));
records.add(new FSButton(FSButton.Over, overShape.getIdentifier(), 2));
records.add(new FSButton(FSButton.Down, downShape.getIdentifier(), 3));

ArrayList actions = new ArrayList();

actions.add(action);
actions.add(action);
actions.add(action);

FSDefineButton button = new FSDefineButton(movie.newIdentifier(), records, actions);
</pre>

<p>3. If more than one button record is defined for a state then the layer number defines the order the shapes are displayed. This allows buttons to be "reused" with only the label on the button being changed.</p>

<pre>
FSDefineShape upShape = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, shape1);
FSDefineShape overShape = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, shape2);
FSDefineShape downShape = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, shape3);

// The label shape contains the "text" for the button. Note the text must be 
// drawn as a shape.

FSDefineShape label = new FSDefineShape(movie.newIdentifier(), bounds, lineStyles, fillStyles, shape4);

ArrayList records = new ArrayList();

// Note that the label defined for all of the button's states. This ensures the 
// label is visible at all times when the mouse is moved over the button.

records.add(FSButton(FSButton.Up, upShape.getIdentifier(), 1));
records.add(FSButton(FSButton.Up, label.getIdentifier(), 2));
records.add(FSButton(FSButton.Over, overShape.getIdentifier(), 3));
records.add(FSButton(FSButton.Over, label.getIdentifier(), 4));
records.add(FSButton(FSButton.Down, downShape.getIdentifier(), 5));
records.add(FSButton(FSButton.Down, label.getIdentifier(), 6));

ArrayList actions = new ArrayList();

actions.add(action);
actions.add(action);
actions.add(action);

FSDefineButton button = new FSDefineButton(movie.newIdentifier(), records, actions);
</pre>

<h1 class="datasheet">History</h1>

<p>The FSDefineButton class represents the DefineButton structure from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 1.</p>
 */
public class FSDefineButton extends FSDefineObject
{
    private ArrayList buttonRecords = null;
    private ArrayList actions = null;
    private byte[] encodedActions = null;

    /**
     * Construct an FSDefineButton object, initalizing it with values decoded 
     * from an encoded object.
     * 
     * @param coder an FSCoder containing the binary data.
     */
    public FSDefineButton(FSCoder coder)
    {
        super(DefineButton, 0);
        decode(coder);
    }
    /**  Constructs an FSDefineButton object with the identifier, button records and actions.

        @param anIdentifier a unique identifier for this button.
        @param buttonRecordArray an array of FSButton objects.
        @param actionArray and array of action objects.
        */
    public FSDefineButton(int anIdentifier, ArrayList buttonRecordArray, ArrayList actionArray)
    {
        super(DefineButton, anIdentifier);
        setButtonRecords(buttonRecordArray);
        setActions(actionArray);
    }
    /**
     * Constructs an FSDefineButton object by copying values from an existing object.
     *
     * @param obj an FSDefineButton object.
     */
    public FSDefineButton(FSDefineButton obj)
    {
        super(obj);
        
        buttonRecords = new ArrayList();
        
        for (Iterator i = obj.buttonRecords.iterator(); i.hasNext();)
            buttonRecords.add(((FSButton)i.next()).clone());

        if (actions != null)
        {
            actions = new ArrayList();
            
            for (Iterator i = obj.actions.iterator(); i.hasNext();)
                actions.add(((FSActionObject)i.next()).clone());
        }
        else
        {
            encodedActions = Transform.clone(obj.encodedActions);
        }
    }

    /**  
     * Constructs an FSDefineButton object with the identifier, button records and 
     * encoded actions.
     * 
     * @param anIdentifier a unique identifier for this button.
     * @param buttonRecordArray an array of FSButton objects.
     * @param bytes an array of encoded action objects.
     */
    public FSDefineButton(int anIdentifier, ArrayList buttonRecordArray, byte[] bytes)
    {
        super(DefineButton, anIdentifier);
        setButtonRecords(buttonRecordArray);
        setEncodedActions(bytes);
    }

    /** Adds the button record object to the array of button records.

        @param aButtonRecord an FSButton object.
        */
    public void add(FSButton aButtonRecord)
    {
        buttonRecords.add(aButtonRecord);
    }

    /** Adds the action object to the array of actions.

        @param anAction an object belonging to a class derived from FSActionObject.
        */
    public void add(FSActionObject anAction)
    {
        if (encodedActions != null)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -