Hello, i need a sprite to have a scrollbar to scroll it’s content in my html5 game.
I tried using eclecticdesignstudio scrollbar but i just can’t make it work!
http://community.openfl.org/t/easy-way-to-add-scrollbar/6656/2
I tried following this example but nothing happens with my target, that is my scroll that i want to scroll.
Can somebody help me or tell me a way to have a sprite component to scroll?
Here is my code:
var _rect:Sprite = new Sprite();
_rect.graphics.beginFill(0xFF0000);
_rect.graphics.drawRect(0,0,100,800);
_rect.graphics.endFill();
var text:TextField = new TextField();
text.text = "teste de scroll";
_rect.addChild(text);
st = new Sprite();
st.graphics.beginFill(0x00FF00);
st.graphics.drawRect(0,0,20,20);
st.graphics.endFill();
sh = new Sprite();
sh.graphics.beginFill(0x0000FF);
sh.graphics.drawRect(0,0,20,100);
sh.graphics.endFill();
scrollbar = new Scrollbar (Scrollbar.VERTICAL, sh, st);
scrollbar.setTarget (_rect, "y", -_rect.height + stage.stageHeight, 0);
addChild(_rect);
I’ve been using the stablexui library and it works great for things like this. I have not been able to get haxeui to work. But stablexui is pretty easy to set up and get it working.
1 Like
Any link from where i can get it the right way or how? c:
I got it working with a few changes
package;
import com.eclecticdesignstudio.ui.Scrollbar;
import openfl.display.Sprite;
import openfl.text.TextField;
class Main extends Sprite {
public function new () {
super ();
var _rect:Sprite = new Sprite();
_rect.graphics.beginFill(0xFF0000);
_rect.graphics.drawRect(0,0,100,800);
_rect.graphics.endFill();
var text:TextField = new TextField();
text.text = "teste de scroll";
_rect.addChild(text);
var st = new Sprite();
st.graphics.beginFill(0x00FF00);
st.graphics.drawRect(0,0,20,stage.stageHeight);
st.graphics.endFill();
st.x = 100;
addChild (st);
var sh = new Sprite();
sh.graphics.beginFill(0x0000FF);
sh.graphics.drawRect(0,0,20,100);
sh.graphics.endFill();
sh.x = 100;
addChild (sh);
var scrollbar = new Scrollbar (Scrollbar.VERTICAL, st, sh);
scrollbar.setTarget (_rect, "y", 0, -_rect.height + stage.stageHeight);
addChild(_rect);
}
}
I started by testing on the Neko target, which was crashing due to reflection. You may need these changes:
2 Likes
OMGGGG, thanks so much dude omg, you rock!!!1
1 Like