Pull image from library with AS3?

  • RockmanTV
  • Proficient
  • Proficient
  • RockmanTV
  • Posts: 348

Post 3+ Months Ago

Hello, I'm a fairly experienced AS2 programmer transitioning in progress to AS3 programmer. I'm using Flash CS4 as my IDE with Actionscript 3 and Flash Player 10. I'm working on a bigger project but the area I'm struggling in is dynamically pulling an image from the flash library (already loaded). I've been finding the same answers to my question all over and they seem to keep producing the same error so apparently I'm just not getting some little detail. I have an image loaded in the library called test1.jpg. I've right clicked on it and selected 'Export for ActionScript' and 'Export in frame 1'. The class is 'MyMc' and the Base class is 'flash.display.BitmapData'. My code is the following:
Code: [ Select ]
var mc:MyMc = new MyMc();
addChild(mc);
  1. var mc:MyMc = new MyMc();
  2. addChild(mc);

and it produces the following errors:
Quote:
1136: Incorrect number of arguments. Expected 2.
1067: Implicit coercion of a value of type MyMc to an unrelated type flash.display:DisplayObject.


I get these errors, yet this is the answer I see posted all over. The code itself makes sense, just doesn't work like everyone says it should. Help???
  • ukaman
  • Born
  • Born
  • ukaman
  • Posts: 1

Post 3+ Months Ago

import flash.display .* / / import class display.
/ / Your code
1. var mc: MyMc = new MyMc ();
2. addChild (mc);

---------------
with it should pull ..
  • RockmanTV
  • Proficient
  • Proficient
  • RockmanTV
  • Posts: 348

Post 3+ Months Ago

I figured it was as simple as importing a class. Unfortunately, when you're looking up tutorials on the web, they seem to lack the classes required to pull of the operations.

Even if they are basic, switching from AS2 to AS3 is a pain when you're dealing with all these classes to do basic operations that you could do without importing classes in AS2. Thanks for your help Ukaman!
  • RockmanTV
  • Proficient
  • Proficient
  • RockmanTV
  • Posts: 348

Post 3+ Months Ago

Actually... when I went to try this out it didn't work and gave me the same errors. This is my code:

Code: [ Select ]
import flash.display.*
var mc: MyMc = new MyMc();
addChild(mc);
  1. import flash.display.*
  2. var mc: MyMc = new MyMc();
  3. addChild(mc);


Flash CS4 is really starting to annoy me. Why is it so difficult to pull an image from the library to the stage?
  • RockmanTV
  • Proficient
  • Proficient
  • RockmanTV
  • Posts: 348

Post 3+ Months Ago

Ok for anyone who is asking the same question I found the answer.

The arguments the first line was looking for are width and height. After that, we have to cast the jpg in the library as a bitmap data type. So here's the code:

Code: [ Select ]
var bdata = new MyMc(stage.stageWidth, stage.stageHeight);
var bmp = new Bitmap(bdata);
addChild(bmp);
  1. var bdata = new MyMc(stage.stageWidth, stage.stageHeight);
  2. var bmp = new Bitmap(bdata);
  3. addChild(bmp);

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 3 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.