public override void defineButton2(DefineButton tag) { if (tag.condActions.Length > 0) { for (int i = 0; i < tag.condActions.Length; i++) { ButtonCondAction cond = tag.condActions[i]; recordActions(cond.actionList); } } }
/// <summary> /// Parses this object out of a stream /// </summary> protected override void Parse() { // We cannot parse code using the ParseCode() method, due to the // ButtonCondAction format BinaryReader2 br = new BinaryReader2( this._dataStream ); long rememberStreamBegin = this._dataStream.Position; this._buttonID = br.ReadUInt16(); BitStream bits = new BitStream( this._dataStream ); uint reserved = bits.GetBits( 7 ); if ( 0 != reserved ) { throw new SwfFormatException( "DefineButton2 uses reserved bits" ); } this._trackAsMenu = ( 0 != bits.GetBits( 1 ) ); // Quote form spec: "Offset in bytes from start of this // field to the first BUTTONCONDACTION, or 0 if no actions occur" long rememberActionOffset = this._dataStream.Position; this._actionOffset = br.ReadUInt16(); while ( 0 != br.PeekByte() ) { ButtonRecord2 b = new ButtonRecord2( this.Version ); b.Parse( this._dataStream ); this._characters.Add( b ); } // CharacterEndFlag br.ReadByte(); // // Now, we can check the ActionOffset value // this._actions = new List<ButtonCondAction>(); if ( 0 != this._actionOffset ) { if ( ( rememberActionOffset + this._actionOffset ) != this._dataStream.Position ) { SwfFormatException e = new SwfFormatException( "ActionOffset was 0x" + this._actionOffset.ToString( "X02" ) + " at stream position 0x" + rememberActionOffset.ToString( "X08" ) + " but stream is now at 0x" + this._dataStream.Position.ToString( "X08" ) ); Log.Error(this, e ); throw e; } ButtonCondAction cond = null; do { cond = new ButtonCondAction( this.Version ); try { uint bytesLeft = ( uint )( this._tag.Length - ( this._dataStream.Position - rememberStreamBegin ) ); cond.Parse( this._dataStream, bytesLeft ); } catch ( AVM1.AVM1Exception be ) { Log.Error(this, be ); if ( SwfFile.Configuration.AVM1DeleteInvalidBytecode ) { cond.Code.Clear(); } else { SwfFormatException swfe = new SwfFormatException( "DefineButton2 contains invalid ActionCode", be ); throw swfe; } } this._actions.Add( cond ); } while ( cond._OffsetToNextCondAction != 0 ); } // // Scan the _SwfFile for a FileAttributes tag and see if it // specifies AS3. Spec quote: "Starting with Swf 9, if the ActionScript3 field // of the FileAttributes tag is 1, there must be no BUTTONCONDACTION fields in // the DefineButton2 tag. ActionOffset must be 0." // // TODO: implement me if ( this._dataStream.Position != this._dataStream.Length ) { SwfFormatException e = new SwfFormatException( "DefineButton2 has not fully consumed stream (" + this._dataStream.Position.ToString( "d" ) + " of " + this._dataStream.Length.ToString( "d" ) ); Log.Error(this, e ); throw e; } //Log.Debug(this, this.ToString() ); }