From 63a5f573cd2094256c357a13cd557d7354fb2914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Tue, 30 Mar 2021 22:42:55 +0200 Subject: [PATCH] AS1/2 button action execution --- .../decompiler/flash/gui/ImagePanel.java | 37 +++++++++++++++++-- .../flash/gui/player/PlayerControls.java | 10 ++--- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 2eb9df621..083ebfcf6 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -46,6 +46,9 @@ import com.jpexs.decompiler.flash.types.MATRIX; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SOUNDINFO; import com.jpexs.decompiler.flash.exporters.commonshape.ExportRectangle; +import com.jpexs.decompiler.flash.tags.DefineButton2Tag; +import com.jpexs.decompiler.flash.tags.DefineButtonTag; +import com.jpexs.decompiler.flash.types.BUTTONCONDACTION; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Cache; import com.jpexs.helpers.Reference; @@ -1329,6 +1332,32 @@ public final class ImagePanel extends JPanel implements MediaDisplay { if (sounds != null && sounds.buttonSoundChar2 != 0) { // OverUpToOverDown playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar2), sounds.buttonSoundInfo2, timer); } + List actions = new ArrayList<>(); + if (button instanceof DefineButton2Tag) { + DefineButton2Tag button2 = (DefineButton2Tag) button; + for (BUTTONCONDACTION ca : button2.actions) { + if (ca.condOverUpToOverDown) { //press + actions.add(ca.actionBytes); + } + } + } + if (button instanceof DefineButtonTag) { + DefineButtonTag button1 = (DefineButtonTag) button; + actions.add(button1.actionBytes); + } + + for (ByteArrayRange actionBytes : actions) { + try { + int prevLength = actionBytes.getPos(); + SWFInputStream rri = new SWFInputStream(swf, actionBytes.getArray(), 0, prevLength + actionBytes.getLength()); + if (prevLength != 0) { + rri.seek(prevLength); + } + execute(rri); + } catch (IOException ex) { + Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex); + } + } } } } @@ -1634,7 +1663,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { @Override public synchronized int getCurrentFrame() { - return frame; + return frame + 1; } @Override @@ -2472,14 +2501,14 @@ public final class ImagePanel extends JPanel implements MediaDisplay { return; } Timeline timeline = timelined.getTimeline(); - if (frame >= timeline.getFrameCount()) { + if (frame > timeline.getFrameCount()) { return; } - if (frame < 0) { + if (frame < 1) { return; } - this.frame = frame; + this.frame = frame - 1; this.prevFrame = -1; stopInternal(); redraw(); diff --git a/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java b/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java index 1843bc1de..44b6be150 100644 --- a/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java +++ b/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java @@ -338,8 +338,8 @@ public class PlayerControls extends JPanel implements MediaDisplayListener { //updateZoom(); int totalFrames = display.getTotalFrames(); int currentFrame = display.getCurrentFrame(); - if (currentFrame >= totalFrames) { - currentFrame = totalFrames - 1; + if (currentFrame > totalFrames) { + currentFrame = totalFrames; } float frameRate = display.getFrameRate(); Zoom zoom = display.getZoom(); @@ -373,13 +373,13 @@ public class PlayerControls extends JPanel implements MediaDisplayListener { } else { progress.setMaximum(totalFrames - 1); progress.setMinimum(0); - progress.setValue(currentFrame); + progress.setValue(currentFrame - 1); progress.setIndeterminate(false); } - frameLabel.setText(Integer.toString(currentFrame + 1)); + frameLabel.setText(Integer.toString(currentFrame)); totalFrameLabel.setText(Integer.toString(totalFrames)); if (frameRate != 0) { - timeLabel.setText("(" + formatMs((int) (currentFrame * 1000.0 / frameRate)) + ")"); + timeLabel.setText("(" + formatMs((int) ((currentFrame - 1) * 1000.0 / frameRate)) + ")"); totalTimeLabel.setText("(" + formatMs((int) (totalFrames * 1000.0 / frameRate)) + ")"); } if (totalFrames <= 1 && playbackControls.isVisible()) {