-
Instead of using addFrameScript, you could add the script on the actual frames.
So on the r0 frame, you'd have script like:
Code:
roomName_lb.text = rN;
This should work because roomName_lb is defined on that frame, and rN is defined as a property of RowClass.
-
ok I try that but something that I want to confirm.
shouldn't getChildByName have container name infront. Thats why it can't find the label?
something like below.
manageRows is movieClip with name manageRows. Class RowClass and in its time line 2 labels are used.
manageRows.getChildByName('roomName_lb');
-
No, if your manageRows instance is an instance of RowClass. Using it as I did is equivalent to
Code:
this.getChildByName
which since this in that context IS manageRows, that should be what you want.
You could NOT use
Code:
manageRows.getChildByName
within the RowClass because RowClass does not have a manageRows property.
-
var rnlb:MovieClip = MovieClip(getChildByName('roomName_lb'));
rnlb.text = rN;
This is the robust way to do this. I should be exploring more on it. There must a way to access the Label in a movieClip like you do. Can you suggest me where to look for this to solve my problem? or should I change my movieClip structure something to use aabove code?
Thanks for all your help.
-
When you mix frame script and classes, you get weird interactions like things not being defined when you think they should be. This is because flash does some stuff in the background to turn your frame script into functions that are put on the instance via addFrameScript.
You could simply check that you actually got something before manipulating it:
Code:
var rnlb:MovieClip = MovieClip(getChildByName('roomName_lb'));
if (rnlb){
rnlb.text = rN;
}
That will prevent the error, but the real problem is that you need to call that function at some other time. It looks like you've set some properties via the constructor that you want to use to set labels at runtime. Since those labels only exist in the frames they are defined on, you have to manipulate them on those frames.
One way is to put the manipulation code on those frames. This is probably the most straightforward.
Another way is to use addFrameScript. This is essentially the same as above, but from within your class.
And a third way is to put an Event.ENTER_FRAME listener in your class, which monitors for those children, and initializes them if found.
One other avenue to explore would be declaring variables for those labels in the class. I am not sure if flash will properly intialize them on the frames where those labels exist. But it's worth a shot.
-
addFrameScript
Can you give me one example how to use it. To find one label as I want to access label from Classes dynamically. Give me something to look into it deeper and play with it.
One example for my situation. Right now I am googling on it as well.
Thanks
-
addFrameScript requires numeric frame indices. But lets say you wanted to set a function to run on frame 1 and frame 10
Code:
package {
import flash.display.MovieClip;
public class RowClass extends MovieClip
{
var rN:String = "";
var rC:Number = 0;
var ind:Number = 0;
public function RowClass(roomName:String, roomCount:Number, index:Number)
{
rN = roomName;
rC = roomCount;
ind = index;
addFrameScript(0, PrepareRow, 9, PrepareRow);
}
private function PrepareRow():void
{
//should not have to use getChildByName, though it will work.
//var rnlb:MovieClip = MovieClip(getChildByName('roomName_lb'));
roomName_lb.text = rN;
//var rclb:MovieClip = MovieClip(getChildByName('roomCount_lb'));
roomCount_lb.text = rC;
trace("rN=" + rN + " rC=" + rC + " ind=" + ind);
}
}
}
-
Thanks alot for the reply. I been looking around too.
This doesn't work if I put directly roomName_lb.text = rN;
Only one error popping up now.
TypeError: Error #1034: Type Coercion failed: cannot convert fl.controls::Label@20cab0b1 to flash.display.MovieClip.
at RowClass/PrepareRow()
Class is
PHP Code:
package {
import flash.display.MovieClip;
public class RowClass extends MovieClip
{
var rN:String = "";
var rC:Number = 0;
var ind:Number = 0;
public function RowClass(roomName:String, roomCount:Number, index:Number)
{
rN = roomName;
rC = roomCount;
ind = index;
addFrameScript(0, PrepareRow, 9, PrepareRow);
}
private function PrepareRow():void
{
//should not have to use getChildByName, though it will work.
var rnlb:MovieClip = MovieClip(getChildByName('roomname_lb'));
rnlb.text = rN;
var rclb:MovieClip = MovieClip(getChildByName('roomcount_lb'));
rclb.text = rC;
trace("rN=" + rN + " rC=" + rC + " ind=" + ind);
}
}
}
-
wait its working. The name of label is wrong.
Correct is
roomname_lb.text = rN;
let me test and get back to you asap
Thanks
-
Thanks alot. Its working very smooth and now I have concept and can apply it many places. Thanks to you.
In the loop height is jumping like
4.5
105.75
207
and row spacing on y axis is alot. How to fix that?
and Can I use mouseover effect on Row? any way to put in movieClip mouseover effect or its only for buttons?
PHP Code:
for(var i=0; i < 3; i++)
{
var r:RowClass = new RowClass("Room " + i, 500+i, i);
var h:Number = mc_main.height;
trace(h);
r.y = h;
mc_main.addChild(r);
}
-
Apparently your rows are 101.25 pixels tall. Do you perhaps have extra space above or below the row?
-
nope no spaces. Row height is 20 pixel. In between rows I need 1 or 2 pixel space.
-
Did this to achieve the proper height. Is that approach right?
Thanks for all the help. cy later
PHP Code:
var n:Number = 0;
for(var i=0; i < 10; i++)
{
var r:RowClass = new RowClass("Room " + i, 500+i, i);
n += 22;
r.y = n;
mc_main.addChild(r);
}
-
That's certainly one good way.
But try this, just to see whether the rows are as tall as you think they are:
PHP Code:
var n:Number = 0; for(var i=0; i < 10; i++) { var r:RowClass = new RowClass("Room " + i, 500+i, i); trace("row height: "+r.height); n += 22; r.y = n; mc_main.addChild(r);
}
I suspect the rows are much taller than you think they are, perhaps because of the graphics they are associated with.
-
I checked the height from trace("row height: "+r.height); and is showing 101 pixel but myrow height is actually 23 max. I checked it in every way. moved manageRows on stage and height is 23 nowhere I see 101. Am I doing anything wrong?
Thanks
-
Not sure. Since your rows have Labels, they might be like Textfields and have a large size unless the autosize property is set. Try setting
Code:
label.autoSize = TextFieldAutoSize.LEFT;
Where "label" is your actual label. There might be a checkbox for this in the IDE.
-
Yes that height problem is solved with this and grid coming out very good nice.
Onething that I been working on was row color change onmouseover. I have added in manageRow another Frame r2 which has mouseoverRow movieClip to be used as background. Below is the code.
The problem is when I mouse over on row the background contineously blinking.
Is there any better approach to this?. Am I doing right?
Thanks
PHP Code:
public function RowClass(roomName:String, roomCount:Number, index:Number, type:String)
{
this.rType = type;
this.addFrameScript(0, PrepareRow, 9, PrepareRow);
}
private function PrepareRow():void
{
if (rType == "First")
{
this.gotoAndStop("r0");
FirstRow();
}
else if(rType == "Alternate")
{
this.gotoAndStop("r1");
AlternateRow();
}
}
private function FirstRow():void
{
this.firstRow.addEventListener (MouseEvent.MOUSE_OVER, manageMouseOver);
this.firstRow.addEventListener(MouseEvent.MOUSE_OUT, manageMouseOut);
}
private function AlternateRow():void
{
if (alternateRow)
{
this.alternateRow.addEventListener (MouseEvent.MOUSE_OVER, manageMouseOver);
this.alternateRow.addEventListener(MouseEvent.MOUSE_OUT, manageMouseOut1);
}
}
function manageMouseOver(e:MouseEvent):void
{
//e.target.alpha = .7;
this.gotoAndStop("r2");
}
function manageMouseOut(e:MouseEvent):void
{
//e.target.alpha = 1;
this.gotoAndStop("r0");
}
function manageMouseOut1(e:MouseEvent):void
{
//e.target.alpha = 1;
this.gotoAndStop("r1");
}
Would it be better if I use rectangles for the row and change the fillcolor on mouseover and out. Is that better approach?. it would be better if i fix above code.
Last edited by pirzada; 05-31-2009 at 06:02 PM.
-
-
I don't know. I doubt that's the best way, but I don't deal with frame code for precisely this reason. It gets convoluted quickly.
Were I to do it, I'd probably just set and remove a glowfilter instead of going to a new frame. I'm not saying my way is better, I'm just saying I hate frames.
-
Hi,
I have a problem. Listbox is on the stage and I want to customize it. The code is below but its not working and nothing happening. Any help please
PHP Code:
mainRef.roomList_lb.setStyle("backgroundColor", 0xE3FFD6);
mainRef.roomList_lb.setStyle("alternatingRowColors", 0xE3FFD6);
mainRef.roomList_lb.setStyle("borderStyle", "none");
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|