From 746dfd739d8cedfa687074bfbee33ad2d99375f2 Mon Sep 17 00:00:00 2001 From: Nathan Dinsmore Date: Tue, 24 Jun 2014 18:49:23 -0400 Subject: [PATCH] Made renameSprite/renameCostume DRYer --- src/scratch/ScratchRuntime.as | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/scratch/ScratchRuntime.as b/src/scratch/ScratchRuntime.as index 3f79385..6cb8227 100644 --- a/src/scratch/ScratchRuntime.as +++ b/src/scratch/ScratchRuntime.as @@ -678,11 +678,7 @@ public class ScratchRuntime { var oldName:String = costume.costumeName; if (obj.isCostumeNameUsed(newName)) return; costume.costumeName = newName; - var uses:Array = obj.isStage ? allUsesOfBackdrop(oldName) : allUsesOfCostume(oldName); - for each (var a:BlockArg in uses) { - a.setArgValue(newName); - } - app.setSaveNeeded(); + updateArgs(obj.isStage ? allUsesOfBackdrop(oldName) : allUsesOfCostume(oldName), newName); } public function renameSprite(newName:String):void { @@ -694,8 +690,12 @@ public class ScratchRuntime { for each (var lw:ListWatcher in app.viewedObj().lists) { lw.updateTitle(); } - for each (var a:BlockArg in allUsesOfSprite(oldName)) { - a.setArgValue(newName); + updateArgs(allUsesOfSprite(oldName), newName); + } + + private function updateArgs(args:Array, newValue:*):void { + for each (var a:BlockArg in args) { + a.setArgValue(newValue); } app.setSaveNeeded(); }