javascript constructor won't identified Texture2D variable.

javascript constructor won’t identified Texture2D variable.

public var CvrBook1		: Texture2D;

class Book
{
	var ID: int;
	var title: String;
	var cover: Texture2D;
	var width: float;
	var height: float;
	var thickness: float;
	
	function Book(m_ID: int)
	{
		ID = m_ID;
		
		if(ID == 1)
		{
			title = "Book1";

         ////problem here
			cover = CvrBook1;
         ////
			width = 8.0f;
			height = 11.0f;
			thickness = 1.0f;
		}
	
		else
		{
			title = "Empty";
			cover = null;
			width = 0.0f;
			height = 0.0f;
			thickness = 0.0f;
		}
	}
}

Got this error

Assets/Library/Scripts/BookDataOrganizer.js(38,33): BCE0005: Unknown identifier: ‘CvrBook1’.

CvrBook1 is defined outside of your class definition. AFAIK (though I’m not a JS expert) Unity doesn’t allow the use of global variables like this, so you have to declare the variable within your class definition.

If you still want to have global access to it, you can define it as static. Therefore your code would have to look more like

class Book
{
    public static var CvrBook1     : Texture2D;

    // the rest of your code
}