Loading Image Into Bitmapdata
Hi
I am loading bitmapdata from the library like this
linkageId = "landscape"; myBitmapData = BitmapData.loadBitmap(linkageId);
Than attach this bitmap image to a movie.
mc = this.createEmptyMovieClip("mc", 0); mc.attachBitmap(myBitmapData, 0);
Can someone give me the code to load my image using loadMovie instead of from libarary and attach it to movie clip mc.
SitePoint > Design Your Site > Flash and Actionscript
Posted on: Jun 27, 2007, 19:54
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Loading Image Into Bitmapdata
Hi
I am loading bitmapdata from the library like this
linkageId = "landscape";
myBitmapData = BitmapData.loadBitmap(linkageId);
Than attach this bitmap image to a movie.
mc = this.createEmptyMovieClip("mc", 0);
mc.attachBitmap(myBitmapData, 0);
Can someone give me the code to load my image using loadMovie instead of from libarary and attach it to movie clip mc.
Loading Image Into Bitmapdata Using Loadmovie
Hi
I am loading bitmapdata from the library like this
linkageId = "landscape";
myBitmapData = BitmapData.loadBitmap(linkageId);
Than attach this bitmap image to a movie.
mc = this.createEmptyMovieClip("mc", 0);
mc.attachBitmap(myBitmapData, 0);
Can someone give me the code to load my image using loadMovie instead of from libarary and attach it to movie clip mc.
Loading An Image Into A MovieClip, Then Into BitmapData [renamed]
Hello,
I am trying to load an image into a movieclip and then draw the contents of the movieclip to a bitmapData object. Below is some sample code.
Code:
target.jpg_mc.loadMovie(url);
target.createEmptyMovieClip("loader_mc", 100);
target.loader_mc.bmc = target.jpg_mc; // movieclip where to load original image
target.loader_mc.tmc = target.bmp_mc; // movieclip with smoothed image
target.loader_mc.onEnterFrame = function(){
bl = this.bmc.getBytesLoaded();
bt = this.bmc.getBytesTotal();
if (bl >= bt && bt > 4 && this.bmc._width > 0 && this.bmc._height > 0){
//target._parent._visible = true;
this.bmc._visible = false;
var bitmap = new BitmapData(this.bmc._width, this.bmc._height, true);
this.tmc.attachBitmap(bitmap, 100,"auto", true);
bitmap.draw(this.bmc);
Stage.addListener(target);
target.gotoAndPlay("in");
this.removeMovieClip();
}
}
For some reason it always draws a white box rather than the image. Has anyone ever seen this happen with the bitmapData class?
Thanks for any help!
Wade
[F8]copy BitMapData To Duplicate Image = Blurred Image?
I'm making a basic image gallery. I'm reading data about the files from xml which then creates thumbnails. I use the loadMovieClip class to load the images into the thumbnails (I'm loading the full size images but then reducing the size of them to look like thumbnails).
I have figured out how to use the BitMapData class to copy the images into cache so when you click on a thumbnail, it instantly appears, but the resulting larger image has pretty low quality. Is this a result of copying the BitMapData?
Also, I saw on another post that if you load an image once, it will be in your browser's cache so you wouldn't have to download it again. I'm wondering how well that works.
Also, GPARIS, if you read this, what method do you use on your site http://www.genevieveparis.com/client...iemacleod.html ?
I noticed it loads thuimbnail images up but the large images are instantly available and they are sharp/high quality. I thought I read in a post somewhere that you use the bitmap method, but couldn't find the post. If that's the case, is there something you do to make sure the bitmap data comes out sharp after copying? Awesome site by the way.
Thanks for any input.
Load Image Into Bitmapdata
Hi
I am loading bitmapdata from the library like this
linkageId = "landscape";
myBitmapData = BitmapData.loadBitmap(linkageId);
Than attach this bitmap image to a movie.
mc = this.createEmptyMovieClip("mc", 0);
mc.attachBitmap(myBitmapData, 0);
Can someone give me the code to load my image using loadMovie instead of from libarary and attach it to movie clip mc.
BitmapData Of On-stage Image?
If I have a bitmap, let's say a .png, on the Stage at compile time (as opposed to instantiating it), is there a way to access the .png's BitmapData? Many thanks.
Image Transperancy In BitmapData
Folloing are the excerpts of my code in AS2:
I have image1 as and image2 on my stage. The image2 is a transparent GIF and works good transparantly when moved, roatated etc. this image2 is merged over image1 on a button click instance.
Problem with the source is that as soon as the image is merged it (image2) looses its transparancy and converted to opaque again. How to resolve this issue?
Attach Code
on (press) {
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.geom.ColorTransform;
var bmp1:BitmapData = new BitmapData(int(_parent.m1w.text), int(_parent.m1h.text), false, 0x00FFFFFF)
bmp1.draw(_parent.m1, new Matrix());
var bmp2:BitmapData = new BitmapData(int(_parent.m2w.text), int(_parent.m2h.text), false, 0x00FFFFFF);
bmp2.draw(_parent.m2, new Matrix());
var bmpmrgd:BitmapData = new BitmapData(int(_parent.m1w.text)+100, int(_parent.m1h.text), false, 0x00FFFFFF);
bmpmrgd.merge(bmp1, new Rectangle(int(_parent.m1x.text)-40, int(_parent.m1y.text)-10, int(_parent.m1w.text), int(_parent.m1h.text)), new Point(int(_parent.m1x.text), int(_parent.m1y.text)), 250, 250, 250, 100);
bmpmrgd.merge(bmp2, new Rectangle(0, 0, int(_parent.m2w.text), int(_parent.m2h.text)), new Point(int(_parent.m2x.text), int(_parent.m2y.text)), 250, 250, 250, 100);
_parent.createEmptyMovieClip("mrgdclip", _parent.getNextHighestDepth());
_parent.mrgdclip.attachBitmap(bmpmrgd, mrgdclip.getNextHighestDepth());
_parent.m1._visible = false;
_parent.m2._visible = false;
_parent.m1x._visible = false;
_parent.m1y._visible = false;
_parent.m1w._visible = false;
_parent.m1h._visible = false;
_parent.m2x._visible = false;
_parent.m2y._visible = false;
_parent.m2w._visible = false;
_parent.m2h._visible = false;
_parent.b1._visible = false;
}
Image File To BitmapData
Im doing this game as final project for graduation and I want all imagery available and dynamicly loadable from a directory without a need to have it all imported into a library.
So is there a way to load external image and convert it to BitmapData or get its content at pixel level?
[edit]Cause I dont see any. If I load it with loadMovie, it becomes content of a MC and I dont know af any functionality to work with a MC as with a bitmap and any other loading method is not know to me too.[/edit]
BitmapData Of On-stage Image?
If I have a bitmap, let's say a .png, on the Stage at compile time (as opposed to instantiating it), is there a way to access the .png's BitmapData? Many thanks.
BitmapData From Embedded Image?
Hey everyone,
How would you fill a bitmapData with an embedded image?
This is what I have so far. I've read the language reference, but I have no clue as to where to go from here.
Code:
// Embed images
[Embed(source="texture.PNG")]
private var Texture:Class;
private function createBox(x:Number, y:Number, w:Number, h:Number, friction:Number, restitution:Number, static:Boolean, mode:uint, fill:Object):void {
// Modes: 0 - solid fill, 1 - gradient fill, 2 - bitmap fill
trace("function:createBox");
bodyDef = new b2BodyDef();
bodyDef.position.Set(x, y);
boxDef = new b2PolygonDef();
var boxCenter:b2Vec2 = new b2Vec2(w, h);
boxDef.SetAsOrientedBox(w, h, boxCenter);
boxDef.friction = friction;
boxDef.restitution = restitution;
if (static) {boxDef.density = 0;} else {boxDef.density = 1.0;}
bodyDef.userData = new Shape();
if (mode == 0) {
bodyDef.userData.graphics.beginFill(fill);
bodyDef.userData.graphics.lineStyle(0, 0x000000);
bodyDef.userData.graphics.drawRect(0, 0, w, h);
bodyDef.userData.graphics.endFill();
} else if (mode == 1) {
} else if (mode == 2) { /// THIS IS WHERE THE PROBLEM STARTS ///
var bitmapdata:BitmapData = new BitmapData(5, 5, false);
bitmapdata.draw(fill); //bitmapdata.draw(Texture); doesn't work either
bodyDef.userData.graphics.beginBitmapFill(bitmapdata);
bodyDef.userData.graphics.drawRect(0, 0, w, h);
bodyDef.userData.graphics.endFill();
}
bodyDef.userData.width = w * 2 * 30;
bodyDef.userData.height = h * 2 * 30;
addChild(bodyDef.userData);
body = m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
}
It gives me an error that I cannot draw Classes or Objects into bitmapData, but I don't know what else I could do...
Thanks for reading!
Image Class Using BitmapData?
Can someone explain what is going wrong with this simple class:
ActionScript Code:
class image extends MovieClip {
public var bmd:flash.display.BitmapData;
public function image() {
super();
}
public function loadImage(p_url:String, p_loader:MovieClipLoader) {
if (p_url) {
var loadURL:String = p_url;
} else {
var loadURL:String = "/img/"+this._name+".jpg"; //default image location if no URL provided
}
if (p_loader) {
var imageLoader = p_loader;
} else {
var imageLoader = new MovieClipLoader();
trace("making my own loader");
}
imageLoader.addListener(this);
var loadTarget = this.createEmptyMovieClip("loadTarget", this.getNextHighestDepth()); //temporary holder
imageLoader.loadClip(loadURL, loadTarget);
}
function onLoadInit(targetMC:MovieClip) {
trace("loading complete on "+targetMC);
var imgWidth:Number = targetMC._width;
var imgHeight:Number = targetMC._height;
this.bmd = new flash.display.BitmapData(imgWidth, imgHeight, true, 0x00000000);
this.bmd.draw(targetMC);
this.attachBitmap(this.bmd);
targetMC.removeMovieClip();
this._x -= this._width/2;
this._y -= this._height/2;
this._parent.imageLoadComplete(this);
}
function onLoadStart(targetMC:MovieClip) {
trace("loading started on "+targetMC);
}
}
In my library, I have a MovieClip symbol defined type of image and exported in the first frame.
If I don't removeMovieClip(targetMC), I can see that my image loads fine. But when I removeMovieClip, it disappears?
Any help would be greatly appreciated.
Jase
BitmapData Image Resize Does It Have To...
I am creating an environment in my Flash using images as the background. I know how to use the BitmapData to resize images to fit to my screen, but the only way to do this (that I know of) is to load the image into Flash from the library or externally. In this case I would like the images to be in a MC, because I will be animating them with other images and have other animations on top of them. Is there a way to use the BitmapData to fix the scaling image issue in Flash without having to load the images from the Library or externally?
From External Loaded Image To Bitmapdata?
Hey again
I have looked around the forum for a while, but haven't found an answer...
I am loading an external JPG using the Loader class.
And I have this code, that can be used to make a tiled background:
Code:
var backGroundSprite:Sprite = new Sprite();
backGroundSprite.graphics.beginBitmapFill(bitmap);
backGroundSprite.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
backGroundSprite.graphics.endFill();
addChild(backGroundSprite);
I have tried converting the loaded image into a bitmapdata object, but I just can't figure it out. How do I do this?
*************** edit*************
I figured it out with the help of the Flash CS3 help, under the "Bitmap" class:
Code:
var image:Bitmap = Bitmap(myloader.content);
var bitmapData:BitmapData = image.bitmapData;
Dynamically Load An Image To A Bitmapdata
Hi, is there a way to create a bitmapdata from a dynamically loaded jpg or png? I'm searching the documentation and the web and I can't find anything related to this. It seems we can only import images from the library with the BitmapData.loadBitmap method.
Smoothly Resizing An Image By BitmapData
Hello.
I never used BitmapData before but I understand it can be used to smoothly re-size an image.
Does anyone has a code block sample to re-size an image?
I want to smoothly scalle images without having that bad look that it has when an image was scalled inside flash.
Thank you.
- Adrian.
Tiling An Image Using BitmapData.draw()
I'm loading in a large external swf image, and trying to cut it up into stage-sized chunks using BitmapData.draw() with a clipRect parameter, then draw those chunks back onto the stage, essentially producing the same-looking image as the swf.
However, the only thing that is drawing is the first chunk (the one that would appear at 0, 0). The rest are just coming out blank (but in the right spot on the grid).
Here's my code. Anyone know what the problem is?
Code:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest("midgroundBack.swf"));
var tileArray:Array = [];
function onLoadComplete(event:Event):void
{
var l:Loader = event.target.loader as Loader;
var stageWidth:Number = stage.stageWidth;
var stageHeight:Number = stage.stageHeight;
var nColumns:Number = Math.ceil(l.width / stageWidth);
var nRows:Number = Math.ceil(l.height / stageHeight);
trace("Column count: " + nColumns);
trace("Row count: " + nRows);
for (var i:int=0; i<nRows; i++)
{
tileArray[i] = [];
for (var j:int=0; j<nColumns; j++)
{
var rect:Rectangle = new Rectangle(j*stageHeight, i*stageWidth, stageWidth, stageHeight);
var bd:BitmapData = new BitmapData(stageWidth, stageHeight, true, 0x00000000);
bd.draw(l, new Matrix(), new ColorTransform(), "normal", rect);
var bitmap:Bitmap = new Bitmap(bd);
var sprite:Sprite = new Sprite();
sprite.addChild(bitmap);
tileArray[i][j] = sprite;
sprite.x = j * stageWidth;
sprite.y = i * stageHeight;
addChild(sprite);
trace("X: " + sprite.x + ", Y: " + sprite.y);
}
}
}
Essentially, I'm trying to get a grid of stage-sized images rather than one large image.
Thank you,
Eric Smith
Using BitmapData To Display An Image Inside An XML File?
I posted about this already, but I thought I would make this more clear. I'm starting to come to the conclusion that this just can't be done in ActionScript 2.0.
I have a image lets say it's a JPG and I've been able to put it into an array. For example
Code:
import flash.display.BitmapData;
var str:String = "R0lGODlhDwAPAP..."; //Goes on and on
str = Base64.decode( str );
var mc:MovieClip = _root.createEmptyMovieClip( "myclip", 10 );
mc._x = 100;
mc._y = 100;
var bmap:BitmapData = BitmapData.loadBitmap( str );
mc.attachBitmap( bmap, 0 );
So Obviously BitmapData.loadBitmap( str ) Does not work. But is there a way to get otherwise loaded binary image data into a BitmapData object so that it can be used to attachBitmap and be shown?
Thanks,
Smoothly Resizing An Image By BitmapData Is Not Always Work
I have successfully using the following to do the smoothing of external jpg image. e.g. (from 700x525 to 350x262)
1) Load image into a movie clip
2) create a BitmapData object the size of the image in the movie clip
3) use the BitmapData.draw() method to "draw" the image bits from the movie clip into the BitmapData object.
4) Use MovieClip.attachBitmap() to attach the bitmap to a the movieclip that you will be using for your display.
BUT, if I try to scale down a jpg image from 700X525 to even smaller 160x120.....distortion appear again...
Is that we cannot make a perfect and smooth thumbnail from large image?
Really hope that any expert could help thius. thanks
Load Image Into BitmapData Object Dynamically?
I don't know if "dynamically" is the right term, but here's my question:
If I have an XML file that lists the URLs of images (jpegs) that I want to import, is there a way to do load them into BitmapData objects?
I know you can do it if the images are already imported and linked in the library with an identifier...
BitmapData Image Manipulation And Duplicate Movie
I have a question about "Bitmap image manipulation". The file I am working with is the second one listed here. http://www.brendandawes.com/sketches/piecesof8/
I am having trouble getting the code to work when I am duplicating a movie and then attaching it to the "bitmap manipulation code". I think it may be because the duplicated movieclips end up with names like "_level0.promoContainer.p1". Thanks.
ActionScript Code:
loop = 1;
while (loop<=totalPromos) {
promoContainer.p.duplicateMovieClip("p"+loop, loop);
newCont = eval("promoContainer.p"+loop);
newClip = eval("promoContainer.p"+loop+".promo");
if (loop != 1) {
newCont._visible = false;
}
// load jpg's
newClip.loadMovie(promos[loop].path);
++loop;
}
po = _level0.promoContainer.p1;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
myBitmap = new BitmapData(po._width, po._height, true, 0);
myBitmap.draw(this.po);
var myBitmapBlur:BitmapData = myBitmap.clone();
blurMe(myBitmapBlur);
var myBitmapOriginal:BitmapData = myBitmap.clone();
function blurBitmap(target:BitmapData) {
var myfilter = new flash.filters.BlurFilter(8, 8, 2);
target.applyFilter(target, target.rectangle, new Point(0, 0), myfilter);
}
function copy(xPos:Number) {
rect = new Rectangle(0, 0, xPos, myBitmap.height);
blurBitmap(myBitmap);
myBitmap.copyPixels(myBitmapOriginal, new Rectangle(xPos, 0, myBitmap.width-xPos, myBitmap.height), new Point(xPos, 0));
po.attachBitmap(myBitmap, 1, "auto", true);
}
this.onEnterFrame = function() {
copy(po._xmouse);
};
Camera-data To A BitmapData-array - Small Image?
Hello all,
I capture the camera-data to a BitmapData-array. Then use php to save this into a jpeg. This worked for me previously but now it seems to save the image but there is a lot of white space around it. Can someone help me troubleshoot this. Here is a snippet of my code:
ActionScript Code:
var cam:Camera = Camera.getCamera(); // our camera object.
var iFps = cam.fps;
cam.setMode(640, 480, iFps);
cam.setQuality(0,100);
myvideoobject.attachCamera(cam);
var foo:BitmapData = new BitmapData(640,480);
foo.draw(myvideoobject); // this will capture the camera-data to this BitmapData-array
Thanks all
Write Visible Part Of Masked Image To Bitmapdata?
the idea is - a dynamically loaded image is loaded into a movieclip and masked so that just a small area of the entire thing is visible... is there a way to copy that visible area into another movieclip? can it be done with bitmapdata?
Dynamic Image Resize + BitmapData Smoothing = Problem
Hello, I'm brand new to the forums here. I'm okay at actionscript, but honestly everything I'm trying to pull off is beyond me so the fact that I've gotten as far as I have is kind of a feat in itself. Anyway, I'm creating a dynamic image gallery that resizes the images to fit the gallery size, and then smooths them out.
I feel like I'm super close to getting it to work perfectly. The image smoothing always works, but the resizing is kind of iffy. The first image displayed will resize just fine, but when you view any others they're all distorted or squashed. What's strange is that I've traced out the resized image dimensions and they're exactly what they should be, but the images are still not resizing correctly.
Here's my code! I only included the parts of it that are really relevant, but let me know if you guys want to see all of it. It's a combination of a few tutorials that I found. I may be able to provide a live example, but it's for work so I'm not sure how the nondisclosure agreement would affect that.
Thank you so much in advance!
Code:
var thisWidth:Number;
var thisHeight:Number;
var maximumHeight:Number;//height to which movieclip to be resized
var maximumWidth:Number;//width to which movieclip to be resized
var oldx:Number;
var oldy:Number;
var ratio:Number;
var mclis:Object = new Object();//An object that listens for a callback notification from the MovieClipLoader event handlers.
function nextImage() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
loadBitmapSmoothed(image[p], picture);
slider.cap_txt.text = "Photo By: " + author[p];
slider.desc_txt.text = caption[p];
header_txt.text = header[p];
picture_num();
trace(current_pos);
if (sliderval == 1){
var xPosT:Tween = new Tween(slider, "_y", Regular.easeOut, slider._y, 235, .5, true);
sliderval = 0;
}
}
}
}
function lastImage() {
//p++;
p = total-1;
picture._alpha = 0;
loadBitmapSmoothed(image[p], picture);
slider.cap_txt.text = "Photo By: " + author[p];
slider.desc_txt.text = caption[p];
header_txt.text = header[p];
picture_num();
trace(current_pos);
if (sliderval == 1){
var xPosT:Tween = new Tween(slider, "_y", Regular.easeOut, slider._y, 235, .5, true);
sliderval = 0;
}
}
function prevImage() {
if (p>0) {
p--;
picture._alpha = 0;
loadBitmapSmoothed(image[p], picture);
delete _root.mc;
slider.cap_txt.text = "Photo By: " + author[p];
slider.desc_txt.text = caption[p];
header_txt.text = header[p];
picture_num();
trace(current_pos);
if (sliderval == 1){
var xPosT:Tween = new Tween(slider, "_y", Regular.easeOut, slider._y, 235, .5, true);
sliderval = 0;
}
}
}
function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
loadBitmapSmoothed(image[0], picture);
slider.cap_txt.text = "Photo By: " + author[0];
slider.desc_txt.text = caption[0];
header_txt.text = header[0];
picture_num();
if (sliderval == 1){
var xPosT:Tween = new Tween(slider, "_y", Regular.easeOut, slider._y, 235, .5, true);
sliderval = 0;
}
}
}
function picture_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}
/////////////////////////////////////
function loadBitmapSmoothed(url:String, target:MovieClip) {
// Create a movie clip which will contain our unsmoothed bitmap
var bmc:MovieClip = target.createEmptyMovieClip("bmc",target.getNextHighestDepth());
// Create a listener which will notify us when the bitmap loaded successfully
var listener:Object = new Object();
// Track the target
listener.tmc = target;
// If the bitmap loaded successfully we redraw the movie into
// a BitmapData object and then attach that BitmapData to the target
// movie clip with the smoothing flag turned on.
listener.onLoadInit = function(mc:MovieClip) {
bitmap.dispose();
_root.thisHeight = mc._height;//loaded movieclip height
_root.maximumHeight = 500;
_root.thisWidth = mc._width;//loaded movieclip width
_root.maximumWidth = 304;
ratio = thisHeight/thisWidth;//calculation ratio to which resize takes place
if (thisWidth>maximumWidth) {
//picture._x = 143-(thisWidth/2);
thisWidth = maximumWidth;
thisHeight = Math.round(thisWidth*ratio);
width_txt.text = thisWidth;
height_txt.text = thisHeight;
}
if (thisHeight>maximumHeight) {
//picture._x = 143-(thisWidth/2);
thisHeight = maximumHeight;
thisWidth = Math.round(thisHeight/ratio);
width_txt.text = thisWidth;
height_txt.text = thisHeight;
}
picture._width = thisWidth;//applying new width
picture._height = thisHeight;//applying new height
//picture._xscale = 60;
//picture._yscale = 60;
//picture._y = -20;
mc._visible = false;
bitmap = new BitmapData(mc._width, mc._height, true);
this.tmc.attachBitmap(bitmap, this.tmc.getNextHighestDepth(),"auto", true);
bitmap.draw(mc);
};
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmc);
// var mcl:MovieClipLoader = new MovieClipLoader();//MovieClipLoader class lets you implement listener callbacks that provide status information while SWF, JPEG, GIF, and PNG files are being loaded into movie clips.
// mcl.addListener(mclis);//add the object as listener for event handlers
// _root.createEmptyMovieClip("holder_mc", _root.getNextHighestDepth());//holder movieclip
// _root.mcl.loadClip("http://www.atpm.com/11.02/nature/images/blue-flower.jpg", _root.holder_mc);//You can use the loadClip() method to load one or more files into a single movie clip or level;
};
Stretching Image To Size Of Browser Using BitmapData Class And Dawing Api
Ive been working from a great tutorial found at http://www.gotoandlearn.com/download.php on creating full browser flash. It uses the BitmapData class and drawing api to attach an image to the stage and have the image tile when the browser window is resized. The problem is that I want my image to stretch to fit the browser window instead of tile.
I've looked into alternatives on attaching my image to a movieclip and having the mc resize, but thats no good since I'm using the drawing api to draw other elements on the background. The movieclip then covers those other elements.
Any ideas?
import flash.display.BitmapData;
var bgImage:BitmapData = BitmapData.loadBitmap("bgImage");
function fillBG() {
this.beginBitmapFill(bgImage);
this.moveTo (0,0);
this.lineTo (Stage.width,0);
this.lineTo (Stage.width, Stage.height);
this.lineTo (0, Stage.height);
this.lineTo (0,0);
this.endFill ();
}
fillBG();
var stageListen:Object = new Object();
stageListen.onResize = function() {
fillBG();
}
Stage.addListener(stageListen);
Attach Code
import flash.display.BitmapData;
var bgImage:BitmapData = BitmapData.loadBitmap("bgImage");
function fillBG() {
this.beginBitmapFill(bgImage);
this.moveTo (0,0);
this.lineTo (Stage.width,0);
this.lineTo (Stage.width, Stage.height);
this.lineTo (0, Stage.height);
this.lineTo (0,0);
this.endFill ();
}
fillBG();
var stageListen:Object = new Object();
stageListen.onResize = function() {
fillBG();
}
Stage.addListener(stageListen);
BitmapData Expert Required: Transition Between Two Alpha Channel For A Target Image
Hi there,
I'm working on a transition of alpha channel in a target image.
I have one target image and two kind of alpha channel bitmap between which I'm making my transition. The whole works great but unfortunately after having done numerous time the transition back and forth the target image become "burned"... as anyone an idea about it?
Please look at the attachement, I've described precisely my problem in it...
Thank you very much in advance!
Loading A Swf Then Use BitmapData.draw()
I am trying to save a loaded swf as a BitmapData object. Ofcourse this swf is not animated, it just contains an icon or picture. When using the BitmapData.draw() method this does not seem to work, altough this works when i use it on any other mc wich isn't externally loaded. Is this just not possible ?
thnx
BitmapData Loading Issue. Anyone Else Have This?
I load an array of bitmap objects loaded from the internet. Theres about 10.
When I load them in Flash, they load just fine. When you click one, it loads a large one the same way.
When you take it out to HTML , it loads just white blocks ( in the same size as what the images should be).. when you click one of them, a white block comes up, the real thing flashes but goes back to white.. its weird.
BitmapData Prblm For Loading Swf File
hi
i making the photo gallery, here i am using the bitmap data for making some effects between each image when it's start to load.
but in between the images we are using swf files but after applying the effect the swf is not playing..
can any one suggest what i need to make to clear this issue
~~
SK
BitmapData::draw(BitmapData) Doesn't Seem To Support Alpha Channels
Hi all,
I have a BitmapData object with alpha channels, bm1, and would like to draw it into another BitmapData object, bm2. While I can draw bm1 into bm2, alpha channels do not seem to work. Here is some code to illustrate what I'm trying to do:
// create an all-green but semi-transparent BitmapData object (all alphas are set to 0x80 in the constructor)
var bm1:BitmapData = new BitmapData(100, 100, true, 0x8000FF00);
// create an all-white BitmapData object and display it
var bm2:BitmapData = new BitmapData(100, 100, true);
addChild(new Bitmap(bm2));
// draw bm1 into bm2 in the onTimer() callback function
bm2.draw(bm1);
I would expect bm2 to be light-green, because it's semi-transparent, but it's 100% green, i.e., 0xFF00FF00.
I already tried all blend modes, but blend modes didn't make a difference.
Any ideas?
Btw, what I'm trying to do is to extract an arbitrary collection of pixels (as opposed to a rectangle) from a bitmap (bm1) by copying it into another bitmap (bm2) and using alphas of 0x00 and 0xff to select the pixels to be extracted. Is there a better way to do this? (or any way for that matter? ;-)
Thanks!
-Bernd
[F8] Loading A JPeg From File Into BitmapData.loadBitmap()?
Simply put, how can it be done?
I am trying to dynamically load a .jpg file and use it as a background tile. So that means i need to fill the background with that.
Now the only way i know how to do this is with the bitmapdata but that seems to only work for images in the library.. the help file also says "library" and makes no mention of it loading external images. So how can this be done?
Here is the code i use for the image that is on the stage, just for reference.
Code:
import flash.display.BitmapData;
var pattern:BitmapData = BitmapData.loadBitmap("bgTile");
function createTiles():Void {
with (_level0) {
beginBitmapFill(pattern);
moveTo(0, 0);
lineTo(Stage.width, 0);
lineTo(Stage.width, Stage.height);
lineTo(0, Stage.height);
lineTo(0, 0);
endFill();
}
}
Bitmapdata, Save Bandwidth Or Slow Loading?
I've just updated my application with the BitmapData class.
But it's very slow rendering the images after they are loaded. It crashes if I don't put the call to display the next one in an interval. I'm wondering if I should go back to loading the old way. Is anyone else having this trouble?
The code I have is very simple.
Code:
if (libsource.bmap == undefined) {
cp.updateStatus("creating the bitmap for "+libname);
libsource.bmap = new flash.display.BitmapData(libsource._width, libsource._height, true, 0x00000033);
libsource.bmap.draw(libsource);
}
tgmc.attachBitmap(libsource.bmap, 1);
I'm using png 32 images
[as3] Drawing BitmapData To Erase BitmapData
Hey there. I'm still working on my paint program, and I figured I'd try using the open source, raster-based drawing system from Bytearray.org to speed up drawing in some of my paint tools. The Raster class has some drawing functions that don't bother with anti-aliasing, so in some situations, implementing these methods results in faster code than relying on the Graphics package. I've gotten a nice speed boost from my rainbow paintbrush, which is pretty neat. Go open source!
Unfortunately, I can't get the eraser brush to work, even though its code is essentially the same as the other brushes'. And I've figured out why; the "erase" and "alpha" blend modes, which my vector-based eraser uses to erase the drawing surface, don't seem to work when you draw one BitmapData object onto another. I could put the BitmapData in a Bitmap object and draw that, but that's essentially converting raster data to vector, and then back to raster, which is far slower than any speed improvement I'd get from relying on the Raster class in the first place.
Has anyone here succeeded in using one BitmapData object to erase another, without "wrapping" the eraser BitmapData in a Bitmap object?
Dynamically Loading Image Problem (Image Covers Up The Animation)
I am trying to create a movie that uses a dynamically loading jpeg. I have some vertical lines that move across the movie and should go over the jpeg image. The problem I am having is the image covers the effects. I have tried to add "loadMovieNum("images/main_image.jpg", 0);" on Layer 2 and then on Layer 1 I have my animated lines that should go across the jpeg image. The line animation is on the bottom layer, but the image still covers the effects. Am I doing something wrong?
I have attached the .fla file for an example.
Dynamically Load An Image-Either The Image Resizes Or The Movieclip It's Loading To?
I will make a frame movie instance 400 X 400px called frame_mv.
I will use the script:
loadMovie("pic1.jpg", frame_mv);
If the pics being loaded were of different sizes. eg pic1.jpg was 1600 X 800
1- How would I make the pic resize to 400 X 400 or 400 X 200 so that it fits the frame_mv.
2- How would I make the frame_mv change size according to the pic dimensions being loaded?
Loading External Image > Image Appears Invisible
Hé,
I'm not posting here very much, so hi to anyone new.
I tried search for a solution to my problem, but I couldn't find one.
I'm using a button to load an external image:
code: on (Release) {
_root.temp.loadMovie("img.jpg");
}
Don't worry, both img.jpg and _root.temp (a box-shaped MC) excist.
When I press the button, _root.temp should be swaped by the image. Instead, it disappears, but no image appear. I have absolutely no idea what I'm doing wrong! I'm using Flash MX btw.
Here are my files:
http://www.cmd.tech.nhl.nl/users/regne200/test/
Loop While Image Is Loading / Fade Image As It Loads
Hi, another question:
I'm pulling a jpeg into a flash file using this:
loadMovie("digitalP_bg_2.jpg", "holder");
i have a shape over the image which is being pulled in, and this shape is supposed to fade after the jpeg is loaded - i've used straight forward tweening for the fade. howe ever, even though the loadMovie function is placed before the fade on the timeline, the jpeg takes a while to load and so the fade happens before the actual image has loaded.
my action scriptiing is very very minimal, i'd like to know if there's an easy enough solution to this. what i am thinking of possibly is creating a loop while the image is loading - provided that it isn't too complex to detect how much of the image is loaded.
any suggestions?
you can view the fla and swf here:
http://www.ponch.biz/flashtest/
cheers
Ponch
Basic Image View Not Dynamically Loading Image URL
What I have done Is added only a List Component to the stage and named it "lb". Then I'm Dynamically loading the data and label attributes from an external XML file. Now, I am Listening for the change event on 'lb" in order to create a new url request from the data property of the selected 'lb' item. Unfortunately, I am recieving this error message.
1067: Implicit coercion of a value of type flash.net:URLLoader to an unrelated type flash.display:DisplayObject.
Code:
var loader:URLLoader = new URLLoader();
var xml:XML;
var imgLoader:URLLoader;
loader.load(new URLRequest("http://www.xxxxxxx.com/Pictures.xml"));
loader.addEventListener(Event.COMPLETE, onLoaded);
lb.addEventListener(Event.CHANGE, itemChange);
// Loads XML data into List Component LB
function onLoaded(e:Event):void{
xml= new XML(e.target.data);
var il:XMLList = xml.Album[0].image;
for(var i:uint=0; i<il.length(); i++){
lb.addItem({data:il.attribute("url")[i],
label:il.attribute("title")[i]});
}
}
//Passes String used for URL
function loadImage(url:String):void{
imgLoader = new URLLoader();
imgLoader.load(new URLRequest(url));
imgLoader.addEventListener(Event.COMPLETE, imageLoaded);
}
//Creates Sprite from image url passed through loadImage
function imageLoaded(e:Event):void{
var image:Sprite = new Sprite();
image.width = 200;
image.height = 400;
image.x = 200;
image.y = 10;
image.addChild(imgLoader);
}
//OnChange .selected item passes URL String to LoadImage
function itemChange(e:Event):void{
loadImage(lb.selectedItem.data);
}
I'll admit I'm still a little new at this but I was thinking that URLRequest only need a String value wich I should be getting from "lb.selectingItem.data.toString()... atleast thats what it has been tracing. Any help is welcomed and thanks in advance.
Targeting Image Container After Loading Image In
hey guys,
i load an image from an array into a container MC.
after that i want to assign onPress function and read an image that's loaded.
but it seems after its loaded i can't do so, why is that and how do i get around this issue?
ActionScript Code:
loader_MC.loadMovie(_root.imageArray[0]);
//then
loader_MC.onPress = function(){ // this doesn't work as soon as there is an image there.
//do somthing
}
thanks!
Gallery Image Loading - Getting Image Width..help
Ladies and gents:
having a problem with my code somewhere; I'm stumped. Here's what i'm trying to do:
-When you click on a thumbnail in my gallery a load bar appears that is the width of the loading image
-While the image loads the load bar scales from full width to zero
-Once it finishes loading the image fades in
-Click on a new thumbnail, and the old image fades out, then the scrollbar is supposed to take the width of the NEW image and do the same thing
What is happening is that the scrollbar width does not set itself to the new image size until i click the thumbnail a second time...try this link to see what i mean. it's on the "portfolio" page.
http://www.lewisweb.ws/staging
here's the code:
Code:
//CONSTANTS
frame_x = 387; //the exact x coordinate where the box originates
frame_y = 184; //the exact y coordinate where the box originates
alphaSpeed = 5; //spped at which the pics fade in
//INITIAL SETTINGS
containerMC._alpha = 0;
containerMC._x = frame_x;
containerMC._y = frame_y;
//Fades in a picture loaded externally
MovieClip.prototype.loadPic = function(pic){
containerMC.fadeOldPic(); //fade out old picture
containerMC._alpha = 0;
this.loadMovie(pic); //load new pic
var loadIsComplete = false; //reset load checker
var w = containerMC._width;
loadBar._width = w; //set loadbar to new movieclip width
loadBar._alpha = 100; //make loadbar opaque
_root.onEnterFrame = function(){
var t = containerMC.getBytesTotal(), l = containerMC.getBytesLoaded();
loadIsComplete = (Math.round(l/t) == 1); //check to see if load completed
loadBar._width = w - ((l/t) * w); //sets width of loadbar dynamically
if (loadIsComplete){
containerMC._alpha += alphaSpeed; //if load is complete, fade pic in
}
//if the load is complete and the picture is fully faded in...
if (t != 0 && loadIsComplete && _root.containerMC._alpha == 100){
loadBar._alpha = 0; //make the load bar disappear
delete _root.onEnterFrame;
}
}
};
//Fades out an old picture...pretty self explanatory
MovieClip.prototype.fadeOldPic = function(){
_root.onEnterFrame = function(){
_root.containerMC._alpha -= alphaSpeed;
if (_root.containerMC._alpha == 0){
delete _root.onEnterFrame;
}
}
};
containerMC.loadPic("portfolio/westin.jpg");
stop();
ANY help will be appreciated!
Loading Image When The Image Is Created On The Fly
I hope the title made sense.
Off Topic:
If this has been covered elsewhere please let me know and I'll ask a moderator to remove this thread
I am trying to load a gif that represents a graph of Gold Prices. The image in question is updated periodically and can be used as long as it has been unaltered and has the name of the service provider that supplies it along with a few other conditions. It's from Kitco.com.
The image itself can be found here: http://www.kitco.com/images/live/gold.gif
The easiest way to this to my knowledge is to create an empty clip, give it an a name (mcImage) and load the image as follows:
_root.mcImage.loadMovie("http://www.kitco.com/images/live/gold.gif");
* I've used an onClipEvent(load) to fire the loadMovie function.
This should work and works pretty much first time every time whenever I've needed it before but it doesn't work for this one.
Any thoughts?
Thanks,
Dynamic Image Loading / Images Not Loading?
This is my first try at loading images with action script. I read through the forums, borrowed code, and adapted it.
///////////////////////////works fine
myvars = new LoadVars();
myvars.load("alldoorsdesc.txt");
myvars.onLoad = function (success) {
if (success) {
_root.doorsinsttxt.htmlText = myvars.d1txt+"<BR><BR>To order call us at 505 934 8888";
//I would like to create a for loop here so addidtional
//items can be added, is this possible?
_global.dr1txt = myvars.d1txt;
_global.dr2txt = myvars.d2txt;
_global.dr3txt = myvars.d3txt;
_global.dr4txt = myvars.d4txt;
_global.dr5txt = myvars.d5txt;
}
};
///////////////////////////doesn't trace to loaded door
var doormovie = _root.createEmptyMovieClip("imgmovie",_root);
doormovie._y = 100;
doormovie._x = 300;
doormovie._width = 300;
doormovie._height = 300;
function loadpic(num){
trace("inside loadpic" +num);
doormovie.createEmptyMovieClip("img"+num, num);
doormovie["img"+num].loadMovie("images/door"+num+".png");
//// I'm not sure about this line
doormovie["img"+num].onload = function(){trace("loaded door"+num);};
stop();
}
function unloadpic(num){cont["img"+num].removeMovieClip();}
function unloadAll(){cont.removeMovieClip();}
loadpic(1);// load the inital picture
----------------------------
Are all these functions loaded into the root visible from another movie that is imported with getURL ? Or do I have to copy the functions to that imported movie?
[AS] Loading Main Image While Loading Thumbnails
Hello,
I've got a custom gallery of sorts going on and there's a problem with it... There's 146 photos that have thumbnails loaded in and when clicked open up a larger photo in the presentation.
What happens is while the thumbnails are loading, if one that has loaded is clicked, the main image movieclip runs, but the photo itself doesn't load. It won't load until all the thumbnails are loaded in.
Is there a way to tell the clip to load it too? Or interrupt the thumbnail loading process then restart once the loaded image has completed?
Here's what I'm using...
[Thumbnail loader]
ActionScript Code:
stop();
var tSpacer:Number = 100;
var imagesT:Array = [];
var imagesM:Array = [];
var thisWid:Array = [];
var thisHgt:Array = [];
var imgNum:Number = 0;
var loadthis = "http://www.hpiracing.com/swf/2007/b2v/photoloader.php";
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = parseMe;
import flash.display.*;
function loadBitmapSmoothed(url:String, target:MovieClip)
{
// Create a movie clip which will contain our
// unsmoothed bitmap
var bmc:MovieClip = target.createEmptyMovieClip("bmc", target.getNextHighestDepth());
// Create a listener which will notify us when
// the bitmap loaded successfully
var listener:Object = new Object();
// Track the target
listener.tmc = target;
// If the bitmap loaded successfully we redraw the
// movie into a BitmapData object and then attach
// that BitmapData to the target movie clip with
// the smoothing flag turned on.
listener.onLoadInit = function(mc:MovieClip)
{
mc._visible = false;
var bitmap:BitmapData = new BitmapData(mc._width, mc._height, true);
this.tmc.attachBitmap(bitmap, this.tmc.getNextHighestDepth(), "auto", true);
bitmap.draw(mc);
};
listener.onLoadStart = function(targetMC:MovieClip)
{
//trace("started loading "+targetMC);
targetMC._parent.mc_photoPreloader._visible = true;
targetMC._parent.mc_photoPreloader._width = 0;
};
listener.onLoadProgress = function(targetMC:MovieClip, lBytes, tBytes)
{
targetMC._parent.mc_photoPreloader._width = (lBytes/tBytes)*100;
};
listener.onLoadComplete = function(targetMC:MovieClip)
{
border._visible = false;
targetMC._parent.mc_photoPreloader._visible = false;
};
// Do it, load the bitmap now
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url, bmc);
}
function parseMe(success:Boolean):Void
{
trace("XML Loaded");
if(success)
{
thisChild = this.firstChild.firstChild.childNodes;
numItems = thisChild.length;
//trace(thisChild);
//trace("Loading " + numItems + " XML entries...");
for(i=0; i<numItems; i++)
{
//trace(thisChild[i].childNodes[1].firstChild.nodeValue + "
");
randMax = 5;
var rotRand:Number = random(randMax);
var rotRand2:Number = random(randMax);
if(rotRand > (rotRand/2))
{
rotRand2 = -(rotRand2);
}
mc_photoholder.attachMovie("mc_photoLoader", "mc_photoLoader" + i, mc_photoholder.getNextHighestDepth());
mc_photoholder["mc_photoLoader" + i].mc_photoPreloader._visible = false;
mc_photoholder["mc_photoLoader" + i]._y = (tSpacer * i) - 5;
mc_photoholder["mc_photoLoader" + i]._x = rotRand2;
mc_photoholder["mc_photoLoader" + i]._rotation = rotRand2;
//trace("Loading clip " + thisChild[i].childNodes + " into " + mc_photoholder["mc_photoLoader" + i].mc_photohere);
imagesT.push(thisChild[i].childNodes[0].firstChild.nodeValue);
imagesM.push(thisChild[i].childNodes[1].firstChild.nodeValue);
thisWid.push(thisChild[i].childNodes[2].firstChild.nodeValue);
thisHgt.push(thisChild[i].childNodes[3].firstChild.nodeValue);
//var thisWid:Array = [];
//var thisHgt:Array = [];
}
loadImages();
}
}
function loadImages():Void
{
var imgTotal:Number = imagesT.length;
//trace("imgTotal = " + imgTotal);
loadImg = imagesT;
loadBigImg = imagesM;
widths = thisWid;
heights = thisHgt;
for(j = 0; j < imgTotal; j++)
{
thisMc = _root.mc_photobarleft.mc_photoholder["mc_photoLoader" + j];
thisMc._highquality = 2;// = true;
thisMc.which = loadBigImg[j];
//trace("W = " + widths[j] + " and H = " + heights[j]);
thisMc.thisWid = widths[j];
thisMc.thisHgt = heights[j];
//trace("Which = " + thisMc.which);
loadBitmapSmoothed(loadImg[j],thisMc.mc_photohere);
thisMc.onRelease = function()
{
//trace("MC was clicked.");
var bigPicHolderMC:MovieClip = _root.mc_photoBigAnim.mc_bigPhotoHolder.mc_photoBigLoader;
var bigPicMC:MovieClip = bigPicHolderMC._parent._parent;
var bigPicFrameNo:Number = bigPicMC._currentframe;
//trace("Current Frame = " + bigPicFrameNo);
if(bigPicFrameNo == 1)
{
bigPicMC.play();
}
bigPicMC.which = this.which;
bigPicMC.thisWid = this.thisWid;
bigPicMC.thisHgt = this.thisHgt;
//trace("Which = " + this.which);
bigPicMC.unloadPhoto();
bigPicMC.loadBigPic();
}
}
}
mc_photodragger.onPress = function()
{
this.startDrag(false,108,0,108,250);
}
mc_photodragger.onRelease = function()
{
this.stopDrag();
}
mc_photodragger.onReleaseOutside = function()
{
this.stopDrag();
}
mc_photodragger.onEnterFrame = function()
{
//trace(this._y);
}
mc_photoholder.onEnterFrame = function()
{
//0 - 250
var maxDrag:Number = 250;
var curDrag:Number = mc_photodragger._y;
var perc:Number = Math.round(((curDrag/maxDrag)) * (this._height - maxDrag - tSpacer));
//trace("Perc = " + perc)
this._y = -(perc);
}
trace("Loading XML");
myXML.load(loadthis);
[Main Image Loader]
ActionScript Code:
var which:String;
var thisWid:Number;
var thisHgt:Number;
var maxRight:Number = 500;
var keepmoving:Number;
var playStatus:String;
mc_bigPhotoHolder.mc_photoPreloader._visible = false;
mc = new MovieClipLoader();
preload = new Object();
mc.addListener(preload);
function loadBigPic()
{
var thisTarget:MovieClip = this.mc_bigPhotoHolder;
//trace("W = " + this.thisWid + " and H = " + this.thisHgt);
mc.loadClip(this.which, thisTarget.mc_photoBigLoader);
//trace("New num = " + (Number(this.thisWid) + 20));
var bgWid:Number = Number(this.thisWid) + 20;
var bgHgt:Number = Number(this.thisHgt) + 50;
var thisY:Number = Math.round((maxRight - (bgWid - 20))/2);
trace("Moving photo to " + thisY);
thisTarget.mc_photoBigBg._width = bgWid;
thisTarget.mc_photoBigBg._height = bgHgt;
thisTarget._x = thisY;
thisTarget.mc_photoPreloader._y = bgHgt - 20;
}
preload.onLoadStart = function(targetMC)
{
//trace("started loading "+targetMC);
targetMC._parent.mc_photoPreloader._visible = true;
targetMC._parent.mc_photoPreloader._width = 0;
};
preload.onLoadProgress = function(targetMC, lBytes, tBytes)
{
targetMC._parent.mc_photoPreloader._width = (lBytes/tBytes) * thisWid;
trace("thisWid = " + thisWid);
};
preload.onLoadComplete = function(targetMC)
{
border._visible = false;
targetMC._parent.mc_photoPreloader._visible = false;
};
Please let me know if it can be done.
Thanks!
Image Loading
Our website http://www.tbtsun.com (e-commerce) is going public soon. But it is too large! It has many high quality pictures and I wanted to know if there was a way for the images to load as they want to see them! If someone can do this for me or walk me through step-by-step they will recieve much credit on the website. this website with be viewed by thousands!! PLEASE PUT YOUR INPUT! e-mail me at thesmack@optonline.net
Loading Image On The Fly
I'm want to load an image (image1.gif) into a flash movie, by referencing it's name and location - rather than embedding the image onto the actual movie. This would allow me to change the image by creating a new image and replacing the image1.gif file on my machine.
Can anyone help me please !!!!
Image Loading
Friends,
I would like give an option of uploading an image on to a movie (that is on a MC) by the user. Is there a tutorial or any guidance availble??
Thank you very much,
FK
Image Loading
does anybody know how to control when an image loads in a .swf?
all the images are loading when the website is booting up. id like to make them load when they are called
the website is
http://amourdecroix.com.previewmysite.com
aloha
cortland
Loading Bar For Each Image
I have several galleries within my flash movie. The only problem that I have encountered is that I cannot find a way to make the movie show a loading bar while each Large Image loads. you can view the movie at http://apertureiseverything.tripod.com/mainpage.htm. When you click gallery and then click weddings I am trying to first, get a loading bar to appear as the index loads and then make a loading bar appear if you click on any of the index pictures. I have been told to make a separate movie for each image, but then how would I make my Gallery controller move from "previous movie" to "next movie". The way i have it now is that each image is in a frame and the controller goes from previous frame to next frame. What is the best way to accomplish this? THanks
|