(Unity 4.6 beta) Change UI Image source image from code? C#

I need to change the source image (sprite) in my image script attached to my gameobject. Its easy to do manually by just draging an image from my resourses folder to the “source image slot” in inspector, but how do i do it in code? This is my atempt but it oly results in the image changing to just being white (the color i have chosed in inspector).

public Image testImage; // The one that is default when game starts
public void ChangeImage() {

    testImage.sprite = Resources.Load ("newImage") as Sprite;

}

What is really odd is that it doesnt matter if I type “newImage” correctly…? Unity doesnt complain when it loads a non existing imgage in my resourses folder.

If you have an Image sprite already set in Unity3D and you want to change it later you can use overrideSprite:

public void ChangeImage() {
    // Sprite.Create params: Sprite.Create(Texture2D, Rect, Vector2d)
    testImage.overrideSprite = Sprite.Create( Resources.Load<Texture2D>("newImage"), testImage.sprite.rect, testImage.sprite.pivot );
}

Unity returns null if the resource can’t be found. Casting using as will return null if the type is incorrect. An Image component with a null sprite renders white.

I would suggest using the generic version of Resources.Load. I would also suggest logging an error is this is null

Sprite newSprite =  Resources.Load <Sprite>("newImage");
if (newSprite){
    testImage.sprite = newSprite;
} else {
    Debug.LogError("Sprite not found", this);
}