Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
amar

change width and height at runtime

Recommended Posts

hi, 
 
I'm having some trouble changing the dimensions of a loading item after its been created.

var loader:ImageLoader = new ImageLoader("img/photo1.jpg", {name:"photo1", container:this, x:0, y:0, width:100, height:100, onComplete:onImageLoad}); // start with 100x100

changeSrcAndDimensions();

function changeSrcAndDimensions():void
{
     trace("image loaded");

     loader.url = "image/newImage.jpg"; // change new image
     loader.load();

     TweenLite.set(loader.content, {x:0, y:0, width:200, height:200}); // change to 200x200
}

Any ideas?

 

I know i can destroy that loader and init a new one, but I want to create once and reuse.

 

Thanks,

 

 

Link to comment
Share on other sites

Problem solved! 

 

To anyone who has this issue: use "fitWidth", "fitHeight" properties

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

I don't know what results you are getting, but I just tested your code and my newImage.jpg loaded fine at a size of 200 x 200.

 

If you post a zip of your files not working that would be a great help. 

Click the "More Reply Options" button to attach files.

Link to comment
Share on other sites

Thanks Carl, 

 

The code is actually split across quite a few files, I use data models to hold all properties which are parsed from a server side api, and all components are registered through a object pooling manager. so its a bit tricky to post the files. 

 

The code I posted before was just a basic snippet, below is a more closer version to what i'm working with, set the model and it works with loadermax.

 

Oh and by the way, I'm using Flex.

var image:ImageLoader;
			
protected function creationCompleteHandler(event:FlexEvent):void
{
     if(model)
     {
          image = new ImageLoader(model.asset.sourceFile.fileurl, {container:this, x:0, y:0, width:model.transformData.width, height:model.transformData.height, onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
          image.load();
     }
}

//set the asset model
public function set model(value:AssetObjectModel):void
{
     _model = value;
				
     if(model)
     {
          if(model.asset.sourceFile)
          {
               model.asset.sourceFile.fileurl = FileSystemManager.getInstance().resolvePathForDevice(model.asset.sourceFile.fileurl);
          }
	
          if(image)
          {
               TweenLite.set(image.content, {x:model.transformData.x, y:model.transformData.y, width:model.transformData.width, height:model.transformData.height, rotation:model.transformData.rotation, alpha:model.alpha});

               //only load if different url
               if(image.url != model.asset.sourceFile.fileurl)
               {
                    image.url = model.asset.sourceFile.fileurl;
                    image.load();
               }
          }
     }
}

public function get model():AssetObjectModel
{
return _model;
}

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×