#region GenTag
        private void GenTag(ISwfAction tag)
        {
            if(tag.ActionType == SwfActionId.Empty) return;

            switch(tag.ActionType)
            {   
                // Version 3 Tags
                case SwfActionId.GotoFrame :
                {
                    Gen((GotoFrameAction)tag);
                    break;
                }
                case SwfActionId.GetURL :
                {
                    Gen((GetURLAction)tag);
                    break;
                }
                case SwfActionId.WaitForFrame :
                {
                    Gen((WaitForFrameAction)tag);
                    break;
                }
                case SwfActionId.SetTarget :
                {
                    Gen((SetTargetAction)tag);
                    break;
                }
                case SwfActionId.GoToLabel :
                {
                    Gen((GoToLabelAction)tag);
                    break;
                }
                // Version 4 Tags
                case SwfActionId.Push :
                {
                    Gen((PushAction)tag);
                    break;
                }
                case SwfActionId.If :
                {
                    Gen((IfAction)tag);
                    break;
                }
                case SwfActionId.Jump :
                {
                    Gen((JumpAction)tag);
                    break;
                }
                case SwfActionId.GetURL2 :
                {
                    Gen((GetURL2Action)tag);
                    break;
                }
                case SwfActionId.GotoFrame2 :
                {
                    Gen((GotoFrame2Action)tag);
                    break;
                }
                case SwfActionId.WaitForFrame2 :
                {
                    Gen((WaitForFrame2Action)tag);
                    break;
                }
                // Version 5 Tags
                case SwfActionId.ConstantPool :
                {
                    Gen((ConstantPoolAction)tag);
                    break;
                }
                case SwfActionId.DefineFunction :
                {
                    Gen((DefineFunctionAction)tag);
                    break;
                }
                case SwfActionId.With :
                {
                    Gen((WithAction)tag);
                    break;
                }
                case SwfActionId.StoreRegister :
                {
                    Gen((StoreRegisterAction)tag);
                    break;
                }
                // Version 6 Tags
                case SwfActionId.DoInitAction :
                {
                    Gen((DoInitActionAction)tag);
                    break;
                }
                // Version 7 Tags
                case SwfActionId.DefineFunction2 :
                {
                    Gen((DefineFunction2Action)tag);
                    break;
                }
                case SwfActionId.Try :
                {
                    Gen((TryAction)tag);
                    break;
                }
                default :
                {
                    // if is valid action write tag number etc.
                    if(Enum.IsDefined(tag.ActionType.GetType(), tag.ActionType))
                    {
                        w.WriteByte((byte)(tag.ActionType));
                    }
                    else
                    {
                        throw(new InvalidCastException(
                            "Invalid swf action tag: " + ((int)tag.ActionType) ));
                    }
                    break;
                }
            }
        }
        #endregion


        #region Gen GotoFrameAction
        private void Gen(GotoFrameAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Length);
            w.WriteUI16(tag.Frame);

        }
        #endregion
        #region Gen GetURLAction
        private void Gen(GetURLAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Length);
            w.WriteString(tag.UrlString);
            w.WriteString(tag.TargetString);

        }
        #endregion
        #region Gen WaitForFrameAction
        private void Gen(WaitForFrameAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Length);
            w.WriteUI16(tag.Frame);
            w.WriteByte(tag.SkipCount);

        }
        #endregion
        #region Gen SetTargetAction
        private void Gen(SetTargetAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Length);
            w.WriteString(tag.TargetName);

        }
        #endregion
        #region Gen GoToLabelAction
        private void Gen(GoToLabelAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Length);
            w.WriteString(tag.Label);

        }
        #endregion
        #region Gen PushAction
        private void Gen(PushAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            //w.WriteBytes(tag.Type); // PushType
            w.WriteString(tag.StringValue);
            w.WriteFixedBits(tag.FloatValue);
            w.WriteByte(tag.RegisterNumber);
            w.WriteBit(tag.BooleanValue);
            //w.WriteBytes(tag.DoubleValue); // long
            w.WriteUI16(tag.IntegerValue);
            w.WriteByte(tag.Constant8Value);
            w.WriteUI16(tag.Constant16Value);

        }
        #endregion
        #region Gen IfAction
        private void Gen(IfAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.BranchOffset);

        }
        #endregion
        #region Gen JumpAction
        private void Gen(JumpAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.BranchOffset);

        }
        #endregion
        #region Gen GetURL2Action
        private void Gen(GetURL2Action tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            //w.WriteBytes(tag.SendVarsMethod); // UrlSendMethod
            //w.WriteBytes(tag.LoadTarget); // LoadTarget
            w.WriteBit(tag.LoadVariables);

        }
        #endregion
        #region Gen GotoFrame2Action
        private void Gen(GotoFrame2Action tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteBit(tag.SceneBiasFlag);
            w.WriteBit(tag.Play);
            w.WriteUI16(tag.SceneBias);

        }
        #endregion
        #region Gen WaitForFrame2Action
        private void Gen(WaitForFrame2Action tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteByte(tag.SkipCount);

        }
        #endregion
        #region Gen ConstantPoolAction
        private void Gen(ConstantPoolAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Count);
            for(int i = 0; i < tag.ConstantPool.Length; i++)
            {
                w.WriteString(tag.ConstantPool[i]);
            }

        }
        #endregion
        #region Gen DefineFunctionAction
        private void Gen(DefineFunctionAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteString(tag.FunctionName);
            w.WriteUI16(tag.NumParams);
            for(int i = 0; i < tag.Params.Length; i++)
            {
                w.WriteString(tag.Params[i]);
            }
            w.WriteUI16(tag.CodeSize);
            //w.WriteBytes(tag.Statements); // SwfActionCollection

        }
        #endregion
        #region Gen WithAction
        private void Gen(WithAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Size);
            w.WriteString(tag.WithBlock);
            //w.WriteBytes(tag.Statements); // SwfActionCollection

        }
        #endregion
        #region Gen StoreRegisterAction
        private void Gen(StoreRegisterAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Register);

        }
        #endregion
        #region Gen DoInitActionAction
        private void Gen(DoInitActionAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteUI16(tag.Sprite);
            //w.WriteBytes(tag.Actions); // SwfActionCollection

        }
        #endregion
        #region Gen DefineFunction2Action
        private void Gen(DefineFunction2Action tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteString(tag.FunctionName);
            w.WriteUI16(tag.NumParams);
            w.WriteByte(tag.RegisterCount);
            w.WriteBit(tag.PreloadParent);
            w.WriteBit(tag.PreloadRoot);
            w.WriteBit(tag.SuppressSuper);
            w.WriteBit(tag.PreloadSuper);
            w.WriteBit(tag.SuppressArguments);
            w.WriteBit(tag.PreloadArguments);
            w.WriteBit(tag.SuppressThis);
            w.WriteBit(tag.PreloadThis);
            w.WriteBit(tag.PreloadGlobal);
            //w.WriteBytes(tag.Parameters); // RegisterParams[]
            w.WriteUI16(tag.codeSize);

        }
        #endregion
        #region Gen TryAction
        private void Gen(TryAction tag)
        {
            w.WriteByte((byte)(tag.ActionType));
            w.WriteBit(tag.CatchInRegister);
            w.WriteBit(tag.FinallyBlock);
            w.WriteBit(tag.CatchBlock);
            w.WriteUI16(tag.TrySize);
            w.WriteUI16(tag.CatchSize);
            w.WriteUI16(tag.FinallySize);
            w.WriteString(tag.CatchName);
            w.WriteUI16(tag.CatchRegister);
            //w.WriteBytes(tag.TryBody); // SwfActionCollection
            //w.WriteBytes(tag.CatchBody); // SwfActionCollection
            //w.WriteBytes(tag.FinallyBody); // SwfActionCollection

        }
        #endregion