Copy link to clipboard
Copied
q1)where do i set screen dimensions?
q2)how can i set the images position on screen without using the imageLoaded function because I need to display many images and dont want to create this imageLoaded for every image.
package
{
import flash.display.Sprite;
public class atest1 extends Sprite
{
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public function atest1()
{
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(new URLRequest("ladybug.png"));
//loader.x=200;
//loader.y=100;
}
private function imageLoaded(event:Event):void
{
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
addChild(image);
//image.x=200;
//image.y=10;
}
}
}
var li:atest1= new atest1 ()
Copy link to clipboard
Copied
You can use a double loop and increase
x and y positions for every loader.
Copy link to clipboard
Copied
NOt sure wheat you mean
can you give me an exampe?
Copy link to clipboard
Copied
here is an example (with just one loop):
var array:Array=["url1","url2","url3"]; // u should fill that array somehow with more data...
var wid:Number=150;
var hei:Number=100;
var x_counter:int=0;
var y_counter:int=0;
var columns:int=4;
function loaderFunc():void{
for (var i:Number = 0; i < array.length; i++){
var thumb_url = array.toString();
var thumb_loader = new Loader();
thumb_loader.load(new URLRequest(thumb_url));
thumb_loader.x = (wid+10)*x_counter;
thumb_loader.y = (hei+10)*y_counter;
addChild(thumb_loader);
if (x_counter+1 < columns){
x_counter++;
} else {
x_counter = 0;
y_counter++;
}
}
}
Copy link to clipboard
Copied
An easier way is using paramters in the constructors but it doesnt work??
why does this code fail to load anything without an error?
package
{
import flash.display.Sprite;
public class atest1 extends Sprite
{
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.*;
private var myy:int;
private var myx:int;
private var txt1:TextField = new TextField();
public function atest1(x:int,y:int)
{
var loader:Loader = new Loader;
myx=x;
myy=y;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(
new URLRequest("ladybug.png"));
txt1.text =
"Text1";
addChild(txt1);
import flash.text.*;
}
private function imageLoaded(event:Event):void
{
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
image.x=myx;
image.y=myy;
addChild(image);
}
}
}
var
li:atest1= new atest1(10,200); //doesnt workCopy link to clipboard
Copied
Scene 1, Layer 'Layer 1', Frame 1, Line 1 1198: Attributes are not allowed on package definition.
Scene 1, Layer 'Layer 1', Frame 1, Line 2 1084: Syntax error: expecting identifier before mult.
Scene 1, Layer 'Layer 1', Frame 1, Line 4 1037: Packages cannot be nested.
Scene 1, Layer 'Layer 1', Frame 1, Line 6 1084: Syntax error: expecting identifier before mult.
Scene 1, Layer 'Layer 1', Frame 1, Line 9 1071: Syntax error: expected a definition keyword (such as function) after attribute *, not public.
Scene 1, Layer 'Layer 1', Frame 1, Line 9 1084: Syntax error: expecting rightbrace before leftbrace.
Scene 1, Layer 'Layer 1', Frame 1, Line 50 1071: Syntax error: expected a definition keyword (such as function) after attribute *, not private.
Copy link to clipboard
Copied
You will need again a loop if you wanna use more than one image (and calculate each time x and y positions)
Copy link to clipboard
Copied
I thought AS3 was OOP?
I cant pass paramters in constructors so I need to pass them when an imge is loaded .
If I need to load 3 images how do i do this in as3 without constructors????
var li:atest1= new atest1("img1");
var li:atest1= new atest1("img2");
var li:atest1= new atest1("img3");
Copy link to clipboard
Copied
it works.
You need to use:
var li:atest1= new atest1(10,200);
addChild(li);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
no it doesnt work.
Here is my whole code and I get1 error with addchild
package
{
[
SWF(backgroundColor="blue", width="400",height="300")]
import flash.display.Sprite;
public class atest1 extends Sprite
{
[
SWF(backgroundColor="0x00ff00", width="400",height="300")]
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.*;
private var myy:int;
private var myx:int;
private var txt1:TextField = new TextField();
private var img1:String;
public function atest1(myimage:String)
{
var loader:Loader = new Loader;
img1=myimage;
myx=100;
myy=100;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(
new URLRequest(img1));
}
private function imageLoaded(event:Event):void
{
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
image.x=myx;
image.y=myy;
addChild(image);
}
}
}
var li:atest1= new atest1("ladybug.png");
var addChild(li);
Copy link to clipboard
Copied
it works.
Please download my example (fla+as) and test it.
Copy link to clipboard
Copied
I have flashbuilder and
my code has changed a little since then as you can see.
Could you try my current code where I want to load a file by passing the filename in the constructor?
Might be flashbuilder is no good.
Copy link to clipboard
Copied
i cant open fla files so could you paste it?
Copy link to clipboard
Copied
I did it before:
codes in fla file:
var aa:atest1=new atest1(33,44);
addChild(aa);
The .as file is in the Rar file and with Flashbuilder you can open it.
Copy link to clipboard
Copied
Hi,
no no that is not the file that is old code and I get an error with addchild in flashbuilder
What I wanted to do is pass the string of the image to display
package
Copy link to clipboard
Copied
I suspect my flashbuilder isnt working so could some one try my code on the next post above and just load any image.
I spent hours on this and all I need is someone to verify if this does work.
Then I can look at my installation.