actionscript 3 - Variable embedded source AS3 -
i'm making little memory game multiple themes cards , backgrounds. i've managed make possible 1 set of images embedded game want make possible have more themes. in order make happen use 8 times differen cards:
public var c1:string; [embed(source = c1)] public var card1:class;
with made constructor such:
public function theme( _c1:string) { c1 = _c1; }
now in different class specified themes use constructor such:
var fruit:theme = new theme (".../lib/apple.jpg");
now believe makes new object of theme string c1 source picture , uses string source make picture off of putting in embed source, these error messages:
c1 not have recognized extension, , mimetype not provided. unable transcode c1
how can prevent this?
what you're trying here pass variable (which happens in runtime, after swf compiled) embed metatag preprocessed @ compile time (before application aware of actual theme string value).
there 2 solutions. new swf file per each theme. define resource theme constant, not variable:
[embed(source = 'path/to/resource')]
if want use 1 swf, must rethink application design , load theme @ runtime, initializing loader, fetching resource, creating new theme
resource , start actual game code.
class theme extends eventdispatcher { public static const theme_ready = 'themeready'; private resource:bitmap; public function theme(resourceuri:string) { loadresource(resourceuri); } private function loadresource(path:string):void { var loader:urlloader = new urlloader(new urlrequest(path)); loader.addeventlistener(event.complete, onresourceloaded); } private function onresourceloaded(e:event):void { e.target.removeeventlistener(event.complete, onresourceloaded); this.resource = e.target.content; initialize(); dispatchevent(new event(theme_ready)); } }
game initialization:
var themeresource:string = 'path/to/resource.jpg'; var theme:theme = new theme(themeresource); theme.addeventlistener(theme.theme_ready, initializegame);
Comments
Post a Comment