Made renameSprite/renameCostume DRYer

This commit is contained in:
Nathan Dinsmore 2014-06-24 18:49:23 -04:00
parent 24082315f2
commit 746dfd739d

View file

@ -678,11 +678,7 @@ public class ScratchRuntime {
var oldName:String = costume.costumeName; var oldName:String = costume.costumeName;
if (obj.isCostumeNameUsed(newName)) return; if (obj.isCostumeNameUsed(newName)) return;
costume.costumeName = newName; costume.costumeName = newName;
var uses:Array = obj.isStage ? allUsesOfBackdrop(oldName) : allUsesOfCostume(oldName); updateArgs(obj.isStage ? allUsesOfBackdrop(oldName) : allUsesOfCostume(oldName), newName);
for each (var a:BlockArg in uses) {
a.setArgValue(newName);
}
app.setSaveNeeded();
} }
public function renameSprite(newName:String):void { public function renameSprite(newName:String):void {
@ -694,8 +690,12 @@ public class ScratchRuntime {
for each (var lw:ListWatcher in app.viewedObj().lists) { for each (var lw:ListWatcher in app.viewedObj().lists) {
lw.updateTitle(); lw.updateTitle();
} }
for each (var a:BlockArg in allUsesOfSprite(oldName)) { updateArgs(allUsesOfSprite(oldName), newName);
a.setArgValue(newName); }
private function updateArgs(args:Array, newValue:*):void {
for each (var a:BlockArg in args) {
a.setArgValue(newValue);
} }
app.setSaveNeeded(); app.setSaveNeeded();
} }