Changeset 2783 -- 2011-12-05 01:55:50
- Author
よや
- Comment
- replaceEditTextString メソッドを追加
Diffs
IO_SWF/trunk/sample/swfreplaceedittextstring.php
@@ -0,0 +1,31 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 4) {
+ echo "Usage: php swfreplaceedittextstring.php <swf_file> <id> <initial_text>\n";
+ echo "ex) php swfreplaceedittextstring.php test.swf 1 baa\n";
+ echo "ex) php swfreplaceedittextstring.php test.swf foo baa\n";
+ exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+$id = $argv[2];
+$initialText = $argv[3];
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+$ret = $swf->replaceEditTextString($id, $initialText);
+
+if ($ret === false) {
+ echo "failed to replaceEditTextString($id, $initialText)\n";
+ exit(1);
+}
+
+echo $swf->build();
+
+exit(0);
IO_SWF/trunk/IO/SWF/Editor.php
@@ -552,4 +552,31 @@
array_splice($this->_tags, $target_sprite_tag_idx, 0, $mc_character_tag_list);
return true;
}
+ function replaceEditTextString($id, $initialText) {
+ $this->setCharacterId();
+ foreach ($this->_tags as &$tag) {
+ if ($tag->code == 37) { // DefineEditText
+ if ($tag->characterId === $id) {
+ if ($tag->parseTagContent() === false) {
+ return false;
+ }
+ $tag->tag->initialText = $initialText;
+ $tag->content = null;
+ return true;
+ } else {
+ if ($tag->parseTagContent() === false) {
+ return false;
+ }
+ if ($tag->tag->VariableName === $id) {
+ var_dump($tag);
+ $tag->tag->InitialText = $initialText;
+ $tag->content = null;
+ return true;
+ }
+ }
+ }
+ }
+ trigger_error("Can't found EditText($id)");
+ return false;
+ }
}