Be a Supporter!

Load Inside Container

  • 210 Views
  • 17 Replies
New Topic Respond to this Topic
A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Load Inside Container 2013-11-18 19:07:45 Reply

I have MovieClip called rooms_info that contain these codes and export class rooms_info

import flash.display.Loader;
import flash.net.URLLoader;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.ColorTransform;

stop();

var j = 0;
var pj = 1;
var tc = 0.1;
var myInterval:uint;

var XMLLoader:URLLoader= new URLLoader();
var imgLoader:Loader=new Loader();

var location_txt:TextField= new TextField();
var capacity_txt:TextField= new TextField();
var features_txt:TextField= new TextField();

//Declare Default Format for TextFields
var myFormat:TextFormat = new TextFormat ();

myFormat.align = TextFormatAlign.LEFT;
myFormat.size = 30;
myFormat.color = 0x921818;
myFormat.italic = true;

//Load Format Into TextFields
location_txt.defaultTextFormat=myFormat;
capacity_txt.defaultTextFormat=myFormat;
features_txt.defaultTextFormat=myFormat;

//AutoSize TextFields to Left Side
location_txt.autoSize=TextFieldAutoSize.LEFT;
capacity_txt.autoSize=TextFieldAutoSize.LEFT;
features_txt.autoSize=TextFieldAutoSize.LEFT;

XMLLoader.addEventListener(Event.COMPLETE,onLoaded);

//Declare Color Transform that Effect Alpha of Objects
var my_color:ColorTransform = new ColorTransform();

//Delcare Color Transform Function
function colorEffect():void{
	tc+=0.1;
	if(tc>=1){
		clearInterval(myInterval); 
	}
	my_color.alphaMultiplier=tc;
	
	imgLoader.transform.colorTransform = my_color;
	location_txt.transform.colorTransform = my_color;
	capacity_txt.transform.colorTransform = my_color;
	features_txt.transform.colorTransform = my_color;
	
}



//Change Image Size When Load
imgLoader.contentLoaderInfo.addEventListener(Event.INIT,onInit);
function onInit(evt:Event):void{
	evt.target.content.width = 300;
	evt.target.content.height = 180;
	
}


//Load XML and Image Function
function onLoaded(e:Event):void{

	var myXML= new XML(e.target.data);
	
	imgLoader.load(new URLRequest("rooms/r" + pj + ".jpg"));
	imgLoader.x=110;
	imgLoader.y=10;
	addChild(imgLoader);
	
	location_txt.text="Location: " + myXML.ROOM[j].@LOC;
	capacity_txt.text="Capacity: " +myXML.ROOM[j].@CAP;
	features_txt.text="Features:\n \t";
	
	
		for(var i:uint = 0; i<myXML.ROOM[j].FAC.length(); i++ ){
		features_txt.appendText(myXML.ROOM[j].FAC[i]+"\n \t");
		}
		
	
	location_txt.x = 150;
	location_txt.y = 200;
	
	capacity_txt.x = 150;
	capacity_txt.y = 230;
	
	features_txt.x= 150;
	features_txt.y= 260;
	
	this.addChild(location_txt);
	this.addChild(capacity_txt);
	this.addChild(features_txt);
	
}

XMLLoader.load(new URLRequest("rooms.xml"));

nb.addEventListener(MouseEvent.CLICK,nexth);
pb.addEventListener(MouseEvent.CLICK,Previoush);


function Previoush(e:Event):void{		

var myXML= new XML(XMLLoader.data);

if(j!=0){
	pj--;
	j--;
	
	my_color.alphaMultiplier=0.1;
	tc=0.1;

	removeChild(location_txt);
	removeChild(capacity_txt);
	removeChild(features_txt);
	
	imgLoader.load(new URLRequest("rooms/r" + pj + ".jpg"));
	imgLoader.x=110;
	imgLoader.y=10;
	addChild(imgLoader);
	
	imgLoader.transform.colorTransform=my_color;
	
	location_txt.text="Location: " +myXML.ROOM[j].@LOC;
	capacity_txt.text="Capacity: " +myXML.ROOM[j].@CAP;
	features_txt.text="Features:\n \t";
	
		for(var i:uint = 0; i<myXML.ROOM[j].FAC.length(); i++ ){
		
		features_txt.appendText(myXML.ROOM[j].FAC[i]+"\n \t");
		}
		
	
	location_txt.x = 150;
	location_txt.y = 200;
	
	capacity_txt.x = 150;
	capacity_txt.y = 230;
	
	features_txt.x= 150;
	features_txt.y= 260;
	
	this.addChild(location_txt);
	this.addChild(capacity_txt);
	this.addChild(features_txt);
	
	location_txt.transform.colorTransform = my_color;
	capacity_txt.transform.colorTransform = my_color;
	features_txt.transform.colorTransform = my_color;
	
	myInterval = setInterval(colorEffect,200);
}

else 
{
	pj=myXML.ROOM.length();
	j=(myXML.ROOM.length()-1);

	my_color.alphaMultiplier=0.1;
	tc=0.1;

	removeChild(location_txt);
	removeChild(capacity_txt);
	removeChild(features_txt);
	
	imgLoader.load(new URLRequest("rooms/r" + pj + ".jpg"));
	imgLoader.x=110;
	imgLoader.y=10;
	addChild(imgLoader);
	
	imgLoader.transform.colorTransform=my_color;
	
	location_txt.text="Location: " +myXML.ROOM[j].@LOC;
	capacity_txt.text="Capacity: " +myXML.ROOM[j].@CAP;
	features_txt.text="Features:\n \t";
	
		for(i = 0; i<myXML.ROOM[j].FAC.length(); i++ ){
		
		features_txt.appendText(myXML.ROOM[j].FAC[i]+"\n \t");
		}
		
	
	location_txt.x = 150;
	location_txt.y = 200;
	
	capacity_txt.x = 150;
	capacity_txt.y = 230;
	
	features_txt.x= 150;
	features_txt.y= 260;
	
	this.addChild(location_txt);
	this.addChild(capacity_txt);
	this.addChild(features_txt);
	
	location_txt.transform.colorTransform = my_color;
	capacity_txt.transform.colorTransform = my_color;
	features_txt.transform.colorTransform = my_color;
	
	myInterval = setInterval(colorEffect,200);
}
	
}


function nexth(e:Event):void{
	
var myXML= new XML(XMLLoader.data);

if(j!=(myXML.ROOM.length()-1)){
	pj++;
	j++;

	
	my_color.alphaMultiplier=0.1;
	tc=0.1;

	removeChild(location_txt);
	removeChild(capacity_txt);
	removeChild(features_txt);
	
	imgLoader.load(new URLRequest("rooms/r" + pj + ".jpg"));
	imgLoader.x=110;
	imgLoader.y=10;
	addChild(imgLoader);
	
	imgLoader.transform.colorTransform=my_color;
	
	location_txt.text="Location: " +myXML.ROOM[j].@LOC;
	capacity_txt.text="Capacity: " +myXML.ROOM[j].@CAP;
	features_txt.text="Features:\n \t";
	
		for(var i:uint = 0; i<myXML.ROOM[j].FAC.length(); i++ ){

		
		features_txt.appendText(myXML.ROOM[j].FAC[i]+"\n \t");
		}
		
	
	location_txt.x = 150;
	location_txt.y = 200;
	
	capacity_txt.x = 150;
	capacity_txt.y = 230;
	
	features_txt.x= 150;
	features_txt.y= 260;
	
	this.addChild(location_txt);
	this.addChild(capacity_txt);
	this.addChild(features_txt);
	
	location_txt.transform.colorTransform = my_color;
	capacity_txt.transform.colorTransform = my_color;
	features_txt.transform.colorTransform = my_color;
	
	myInterval = setInterval(colorEffect,200);
}

else 
{
	pj=1;
	j=0;

	
	my_color.alphaMultiplier=0.1;
	tc=0.1;

	removeChild(location_txt);
	removeChild(capacity_txt);
	removeChild(features_txt);
	
	imgLoader.load(new URLRequest("rooms/r" + pj + ".jpg"));
	imgLoader.x=110;
	imgLoader.y=10;
	addChild(imgLoader);
	
	imgLoader.transform.colorTransform=my_color;
	
	location_txt.text="Location: " +myXML.ROOM[j].@LOC;
	capacity_txt.text="Capacity: " +myXML.ROOM[j].@CAP;
	features_txt.text="Features:\n \t";
	
		for( i = 0; i<myXML.ROOM[j].FAC.length(); i++ ){
		features_txt.appendText(myXML.ROOM[j].FAC[i]+"\n \t");
		}
		
	
	location_txt.x = 150;
	location_txt.y = 200;
	
	capacity_txt.x = 150;
	capacity_txt.y = 230;
	
	features_txt.x= 150;
	features_txt.y= 260;
	
	this.addChild(location_txt);
	this.addChild(capacity_txt);
	this.addChild(features_txt);
	
	location_txt.transform.colorTransform = my_color;
	capacity_txt.transform.colorTransform = my_color;
	features_txt.transform.colorTransform = my_color;
	
	myInterval = setInterval(colorEffect,200);
}
	
}

I tried to call the class in another movieclip container
but it only shows my buttons the images that are external doesn't show

var roomclass:MovieClip = new rooms_info();

contain_mc.addChild(roomclass);

contain_mc.x=0;
contain_mc.y=0;

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Load Inside Container 2013-11-18 19:13:24 Reply

At 11/18/13 07:07 PM, A-Genius wrote: I have MovieClip called rooms_info that contain these codes and export class rooms_info

I tried to call the class in another movieclip container
but it only shows my buttons the images that are external doesn't show

You posted a lot of code, but not the class.
You should obviously put your code into the class that you associate with the mc.
If nothing's in the class, that's what happens.

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Load Inside Container 2013-11-18 19:15:36 Reply

At 11/18/13 07:13 PM, milchreis wrote: You posted a lot of code, but not the class.
You should obviously put your code into the class that you associate with the mc.
If nothing's in the class, that's what happens.

that code is the one inside class rooms_info

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Load Inside Container 2013-11-18 19:40:08 Reply

At 11/18/13 07:15 PM, A-Genius wrote: that code is the one inside class rooms_info

It's not a class.
You should try to understand what a class is.
No, you do not just dump your timeline code into a file.

Read "Understanding Classes in As3" Parts 1-4
http://www.untoldentertainment.com/blog/flash-and-actionscript-911/

Btw, setting the position of a newly create DisplayObject as it defaults to 0/0.

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Load Inside Container 2013-11-18 19:48:18 Reply

At 11/18/13 07:40 PM, milchreis wrote:
At 11/18/13 07:15 PM, A-Genius wrote: that code is the one inside class rooms_info
It's not a class.

It's already exported class! for my MovieClip!

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Load Inside Container 2013-11-18 19:59:04 Reply

At 11/18/13 07:40 PM, milchreis wrote:
At 11/18/13 07:15 PM, A-Genius wrote: that code is the one inside class rooms_info
It's not a class.

you don't understood the problem is that I have a movieclip called container_mc and I have another movieclip that is called rooms_info which I can call from my library using the exported class how can I call it to do my code inside room_info!

var roomclass:MovieClip = new rooms_info();

contain_mc.addChild(roomclass);

is it a wrong way to call the whole class?

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Load Inside Container 2013-11-18 20:03:39 Reply

At 11/18/13 07:48 PM, A-Genius wrote: It's already exported class! for my MovieClip!

That does not turn it into a valid class.
As I wrote in my previous post, dumping code into a file does not turn it into a class.
Again, understanding classes is crucial to do this.

I would have appreciated it a lot if you had given my suggestion a try.

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Load Inside Container 2013-11-18 22:36:13 Reply

At 11/18/13 08:03 PM, milchreis wrote:
At 11/18/13 07:48 PM, A-Genius wrote: It's already exported class! for my MovieClip!
That does not turn it into a valid class.
As I wrote in my previous post, dumping code into a file does not turn it into a class.
Again, understanding classes is crucial to do this.

I would have appreciated it a lot if you had given my suggestion a try.

my code was correct! the only problem was with the button I have created was using a problem because was inside a MovieClip.

HappyWhaleStudios
HappyWhaleStudios
  • Member since: Feb. 1, 2013
  • Offline.
Forum Stats
Member
Level 07
Game Developer
Response to Load Inside Container 2013-11-18 22:49:53 Reply

milchreis is right, what you have isn't a class. I'm assuming you're using Flash to write this code, so in your library, right click on the MovieClip that you've linked this class to, and hit Edit Class. There'll be a package, a class, and a constructor in there. Take your code and implement it so that it fits with what's there. The constructor runs when you first create the object, and in order to have variables outside of functions you need to declare them as either private var or public var, and same with functions. Private can't be accessed in other classes, public can. Hopefully this'll help. but you should definitely look into reading what milchreis linked to, coding becomes a lot easier and efficient when you understand and utilize OOP.


BBS Signature
kkots
kkots
  • Member since: Apr. 16, 2013
  • Offline.
Forum Stats
Supporter
Level 10
Blank Slate
Response to Load Inside Container 2013-11-19 08:42:28 Reply

I'd recommend to either actually re-write this whole code as a class or start monkeying around.
For example, debug your code using trace statements in the event handler functions.


BBS Signature
A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Load Inside Container 2013-11-19 08:47:56 Reply

At 11/18/13 10:49 PM, HappyWhaleStudios wrote: milchreis is right, what you have isn't a class. I'm assuming you're using Flash to write this code, so in your library, right

didn't I just said I have completed this part I don't need to define class even thought it's useful! XD I don't really need to involve in classes right now because it was an assignment that I need to complete it without using anything about class just creating external class and work with it! and my codes were 100% correct! I just needed to change the movieclip that I have add inside my button into a graphic that's all! stop talking about class! I don't want to go that deep! we are in my class need to start simple stuff then get us deeper!playing with actual classes are too advanced for me right now!

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Load Inside Container 2013-11-19 09:03:39 Reply

At 11/19/13 08:42 AM, kkots wrote: I'd recommend to either actually re-write this whole code as a class or start monkeying around.
For example, debug your code using trace statements in the event handler functions.

didn't I just said it already ! I HAVE FIXED IT ALREADY! Oh I Actually done these two things to find the problem which is inside my buttons! Thanks for your help but I don't need any right now! Specially that I have already complete it! if I really had another problem I will try to re-write and debug the codes!

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Load Inside Container 2013-11-19 09:20:26 Reply

At 11/19/13 08:47 AM, A-Genius wrote: and my codes were 100% correct!

Nobody denied that at any point in this thread.

You got the advice to use classes properly because it's the better way to do this.
Sadly, you ignore it.

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Load Inside Container 2013-11-19 11:32:40 Reply

At 11/19/13 09:20 AM, milchreis wrote:
At 11/19/13 08:47 AM, A-Genius wrote: and my codes were 100% correct!
Nobody denied that at any point in this thread.

You got the advice to use classes properly because it's the better way to do this.
Sadly, you ignore it.

I am not ignoring the advice it's just I don't want to use it because our teacher have not tough us yet and I can't add something we haven't study yet in the assignment it's better to stick with what the teacher want until we take classes!

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Load Inside Container 2013-11-19 11:35:57 Reply

At 11/19/13 11:32 AM, A-Genius wrote: because our teacher have not tough us yet

That's why I provided the link.

Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Load Inside Container 2013-11-19 12:27:08 Reply

At 11/19/13 11:35 AM, milchreis wrote:
At 11/19/13 11:32 AM, A-Genius wrote: because our teacher have not tough us yet
That's why I provided the link.

He mentioned he can't use anything he hasn't been taught yet for this assignment.

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Load Inside Container 2013-11-19 23:40:28 Reply

At 11/19/13 12:27 PM, Sam wrote:
At 11/19/13 11:35 AM, milchreis wrote:
At 11/19/13 11:32 AM, A-Genius wrote: because our teacher have not tough us yet
That's why I provided the link.
He mentioned he can't use anything he hasn't been taught yet for this assignment.

someone who finally understand me! :D

kkots
kkots
  • Member since: Apr. 16, 2013
  • Offline.
Forum Stats
Supporter
Level 10
Blank Slate
Response to Load Inside Container 2013-11-20 00:55:09 Reply

At 11/19/13 12:27 PM, Sam wrote: He mentioned he can't use anything he hasn't been taught yet for this assignment.

You mean, like, he's not allowed to? I mean, like, even if he learns that himself, uses that himself and clearly explains to the teacher how he learned it and how that works?


BBS Signature