-
1. Re: as3 image load position
Hakan KIRIK Sep 29, 2010 1:57 AM (in response to jagguy999)You can use a double loop and increase
x and y positions for every loader.
-
2. Re: as3 image load position
jagguy999 Sep 29, 2010 3:03 AM (in response to Hakan KIRIK)NOt sure wheat you mean
can you give me an exampe? -
3. Re: as3 image load position
Hakan KIRIK Sep 29, 2010 3:35 AM (in response to jagguy999)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[i].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++;
}
}
}
-
4. Re: as3 image load position
jagguy99 Sep 29, 2010 4:05 AM (in response to Hakan KIRIK)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
-
5. Re: as3 image load position
rkbkbvrkbqfvvkjbqfvkbkqfj Sep 29, 2010 4:21 AM (in response to jagguy99)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. -
6. Re: as3 image load position
Hakan KIRIK Sep 29, 2010 4:24 AM (in response to jagguy99)You will need again a loop if you wanna use more than one image (and calculate each time x and y positions)
-
7. Re: as3 image load position
jagguy99 Sep 29, 2010 4:32 AM (in response to Hakan KIRIK)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");
-
8. Re: as3 image load position
Hakan KIRIK Sep 29, 2010 5:04 AM (in response to jagguy99)it works.
You need to use:
var li:atest1= new atest1(10,200);
addChild(li);
-
-
10. Re: as3 image load position
jagguy99 Sep 29, 2010 5:16 AM (in response to Hakan KIRIK)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);
-
11. Re: as3 image load position
Hakan KIRIK Sep 29, 2010 6:01 AM (in response to jagguy99)it works.
Please download my example (fla+as) and test it.
-
12. Re: as3 image load position
jagguy99 Sep 29, 2010 6:15 AM (in response to Hakan KIRIK)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.
-
13. Re: as3 image load position
jagguy999 Sep 29, 2010 6:26 AM (in response to jagguy99)i cant open fla files so could you paste it?
-
14. Re: as3 image load position
Hakan KIRIK Sep 29, 2010 6:43 AM (in response to jagguy999)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.
-
15. Re: as3 image load position
jagguy999 Sep 29, 2010 7:00 AM (in response to Hakan KIRIK)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
{
import flash.display.Sprite;
public class as2 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();
private var img1:String;
public function as2(myimage:String="")
{
var loader:Loader = new Loader;
this.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);
}
}
}
this.addChild(li); -
16. Re: as3 image load position
jagguy999 Sep 29, 2010 4:59 PM (in response to jagguy999)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.