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

📄 fsmovie.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public void setFrameSize (FSBounds aBounds)
    {
        frameSize = aBounds;
    }

    /** Gets the number of frames played per second that the movie will be displayed at.

        @return the speed the movie will be played at.
        */
    public float getFrameRate()
    {
        return frameRate;
    }

    /** Sets the number of frames played per second that the Player will display the coder.

        @param aNumber the number of frames per second that the movie is played.
        */
    public void setFrameRate (float aNumber)
    {
        frameRate = aNumber;
    }

    /** Gets the array of objects contained in the Movie.

        @return the array of objects that describe a coder.
        */
    public ArrayList getObjects() { return objects; }

    /** Sets the array of objects contained in the Movie.

        @param anArray the array of objects that describe a coder.
        */
    public void setObjects(ArrayList anArray)
    {
        objects = anArray;
    }

    /** Adds the object to the Movie.

        @param anObject the object to be added to the movie.
        */
    public void add(FSMovieObject anObject)
    {
        objects.add(anObject);
    }

    /** Adds all of the objects in the array to the Movie.

        @param array an array of FSMovieObjects.
        */
    public void add(ArrayList array)
    {
        objects.addAll(array);
    }

    /** 
     * Gets an array of objects from the Movie with the specified type. For example 
     * to retrieve all the FSDefineShape objects specified in a movie:

        <pre>
         ArrayList allShapes= aMovie.getObjectsOfType(FSMovieObject.DefineShape);
        </pre>

        Note that only objects at the "top-level" in the movie are checked, namely 
        movie or definition objects. Objects "owned" by another object such as 
        Action objects inside FSDoAction, FSButtonEvent or FSClipEvent objects 
        cannot be retrieved using this method.

        @param aType the type to search the movie for.
        */
    public ArrayList getObjectsOfType(int aType) 
    {
        ArrayList selectedObjects = new ArrayList();
        
        for (Iterator i = objects.iterator(); i.hasNext();)
        {
            FSMovieObject currentObject = (FSMovieObject)i.next();

            if (currentObject.getType() == aType)
                selectedObjects.add(currentObject);
        }
        return selectedObjects;
    }

    /** 
     * Decodes the contents of the specified file. An object for each tag decoded from the file 
     * is placed in the  Movie's object array in the order they were decoded from the file. If 
     * an error occurs while reading and parsing the file then an exception is thrown.
     *
     * @param fileName the path to the Flash file that will be parsed.
     * @throws FileNotFoundException - if an error occurs while reading the file.
     * @throws DataFormatException - if the file does not contain Flash data.
     * @throws FSCoderException - if an error occurs while decoding the file.
     * @throws IOException - if an I/O error occurs while reading the file.
     */
    public void decodeFromFile(String fileName) throws FileNotFoundException, DataFormatException, IOException
    {
        FileInputStream fileContents = null;
        
        File swfFile = new File(fileName);
        
        fileContents = new FileInputStream(swfFile);
        
        int fileLength = (int)swfFile.length();
        byte[] contents = new byte[fileLength];
        
        fileContents.read(contents);
        fileContents.close();
        
        decodeFromData(contents);
    }
    /** 
     * Decodes the contents of the specified file. An object for each tag decoded from the file 
     * is placed in the  Movie's object array in the order they were decoded from the file. If 
     * an error occurs while reading and parsing the file then a message is sent to the 
     * movie listener.
     *
     * @param fileName the path to the Flash file that will be parsed.
     * @param listener an FSMovieListener object where errors messages are
     * sent.
     *
     * @deprecated use the decodeFromFile(String) method which throws an
     * exception if an error is detected.
     * 
     */
    public void decodeFromFile(String fileName, FSMovieListener listener)
    {
        FileInputStream fileContents = null;
        
        try 
        {
            File swfFile = new File(fileName);
            
            fileContents = new FileInputStream(swfFile);
            
            int fileLength = (int)swfFile.length();
            byte[] contents = new byte[fileLength];
            
            fileContents.read(contents);
            fileContents.close();
            
            decodeFromData(contents, listener);
        }
        catch (SecurityException e)
        {
            if (listener != null)
                listener.logEvent(new FSMovieEvent(FSMovieEvent.Decode, FSMovieEvent.Error, 0, 0, "FileNotFoundError"));
        }
        catch (FileNotFoundException e)
        {
            if (listener != null)
                listener.logEvent(new FSMovieEvent(FSMovieEvent.Decode, FSMovieEvent.Error, 0, 0, "FileNotFoundError"));
        }
        catch (IOException e)
        {
            if (listener != null)
                listener.logEvent(new FSMovieEvent(FSMovieEvent.Decode, FSMovieEvent.Error, 0, 0, "FileReadError"));
        }
    }

   /** 
    * Decodes the binary Flash data stored in the byte array. If an error occurs while the data 
    * is being decoded an exception is thrown. The array of objects in the Movie will 
    * contain the last tag successfully decoded.
    *
    * @param bytes an array of bytes that contain the encoded Flash objects.
    * 
    * @throws DataFormatException - if the file does not contain Flash data.
    * @throws FSCoderException - if an error occurs while decoding the file.
    * @throws IOException - if an I/O error occurs while reading the file.
    */
    public void decodeFromData(byte[] bytes) throws DataFormatException, IOException
    {
        FSCoder coder = null;
        FSMovieObject object = null;

        isFlash(bytes);

        if (bytes[0] == 0x43)
            coder = new FSCoder(FSCoder.LITTLE_ENDIAN, unzip(bytes));
        else
            coder = new FSCoder(FSCoder.LITTLE_ENDIAN, bytes);
        
        signature = coder.readString(3, "UTF8");
        version = coder.readWord(1, false);
        /* length */ coder.readWord(4, false);
        frameSize = new FSBounds(coder);
        frameRate = coder.readFixedWord(1, 1);
        frameCount = coder.readWord(2, false);
        
        coder.context[FSCoder.Version] = version;
        coder.context[FSCoder.DecodeActions] = decodeActions ? 1 : 0;
        coder.context[FSCoder.DecodeShapes] = decodeShapes ? 1 : 0;
        coder.context[FSCoder.DecodeGlyphs] = decodeGlyphs ? 1 : 0;
                      
        while ((object = decodeObject(coder)) != null)
        {
            objects.add(object);
            
            if (coder.context[FSCoder.CodingError] == 1)
            {
                throw new FSCoderException(
                    coder.context[FSCoder.TypeInError],
                    coder.context[FSCoder.StartOfError],
                    coder.context[FSCoder.ExpectedLength],
                    coder.context[FSCoder.Delta],
                    (coder.context[FSCoder.Delta] > 0) ? "ObjectOverflow" : "ObjectUnderflow");
            }
        }
        identifier = coder.context[FSCoder.Identifier];
    }

    /** 
     * Decodes the binary Flash data stored in the byte array. If an error occurs while the data 
     * is being decoded a message is sent to the movie listner object. The array of objects in 
     * the Movie will contain the last tag successfully decoded.
     *
     * @param bytes an array of bytes that contain the encoded Flash objects.
     * @param listener an FSMovieListener object where errors messages are
     * sent.
     *
     * @deprecated use the decodeFromData(bytep[]) method which throws an
     * exception if an error is detected.
     */
    public void decodeFromData(byte[] bytes, FSMovieListener listener)
    {
        FSCoder coder = null;
        FSMovieObject object = null;       
        
        try
        {
            isFlash(bytes);
    
            if (bytes[0] == 0x43)
                coder = new FSCoder(FSCoder.LITTLE_ENDIAN, unzip(bytes));
            else
                coder = new FSCoder(FSCoder.LITTLE_ENDIAN, bytes);
        
            coder.context[FSCoder.Action]  = FSMovieEvent.Decode;
            coder.setListener(listener);
            coder.beginObject("FSMovie");
    
            signature = coder.readString(3, "UTF8");
            version = coder.readWord(1, false);
            length = coder.readWord(4, false);
            frameSize = new FSBounds(coder);
            frameRate = coder.readFixedWord(1, 1);
            frameCount = coder.readWord(2, false);
    
            coder.context[FSCoder.Version] = version;
    
            coder.beginObject("ArrayList");
        
            while ((object = decodeObject(coder)) != null)
            {
                objects.add(object);
            }
            
            coder.endObject("ArrayList");
        
            identifier = coder.context[FSCoder.Identifier];
            
            coder.endObject("FSMovie");
        }
        catch (DataFormatException e)
        {
            coder.logError("DataFormatError", 0, 0);
        }
    }
    
    /** 
     * Encodes the array of objects and writes the data to the specified file. If an error occurs 
     * while encoding the file then an exception is thrown.
     *
     * @param fileName the path to the Flash file that the movie will be encoded to.
     *
     * @throws FileNotFoundException - if an error occurs while reading the file.
     * @throws FSCoderException - if an error occurs while encoding the file.
     * @throws IOException - if an I/O error occurs while reading the file.
     */
    public void encodeToFile(String fileName) throws FileNotFoundException, IOException
    {
        FileOutputStream fileContents = null;
        
        fileContents = new FileOutputStream(fileName);
    
        byte[] encodedData = encode();

        fileContents.write(encodedData);
        fileContents.close();
    }
    /** 
     * Encodes the array of objects and writes the data to the specified file. If an error occurs 
     * while encoding the file then a message is sent to the movie listener.
     *
     * @param fileName the path to the Flash file that the movie will be encoded to.
     * @param listener an FSMovieListener object where errors messages are
     * sent.
     *
     * @deprecated use the encodeToFile(String) method which throws an
     * exception if an error is detected.
     */
    public void encodeToFile(String fileName, FSMovieListener listener)
    {
        FileOutputStream fileContents = null;
        
        try 
        {
            fileContents = new FileOutputStream(fileName);
        
            byte[] encodedData = encode(listener);

            fileContents.write(encodedData);
            fileContents.close();
        }
        catch (SecurityException e)
        {
            if (listener != null)
                listener.logEvent(new FSMovieEvent(FSMovieEvent.Encode, FSMovieEvent.Error, 0, 0, "FileNotFoundError"));
        }
        catch (FileNotFoundException e)

⌨️ 快捷键说明

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