Skip to content

Instantly share code, notes, and snippets.

@davidortinau
Created October 22, 2010 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidortinau/641483 to your computer and use it in GitHub Desktop.
Save davidortinau/641483 to your computer and use it in GitHub Desktop.
package {
import reflex.containers.Application;
import reflex.behaviors.TouchScrollBehavior;
import reflex.components.Scroller;
import flash.display.Bitmap;
import flash.display.MovieClip;
/**
* @author David Ortinau <dave@davidortinau.com>
*/
[SWF(backgroundColor="#FFFFFF", frameRate="31", width="1200", height="800")]
public class Demos extends Application {
[Embed(source="../bin/assets/images/ipad_case_01.jpg")]
private var imgCls : Class;
private var photo : MovieClip;
private var scroller : Scroller;
public function Demos() {
scroller = Scroller(this.addChild(new Scroller()));
scroller.width = 400;
scroller.height = 400;
scroller.x = 20;
photo = MovieClip(scroller.addChild(new MovieClip()));
photo.addChild(new imgCls() as Bitmap);
scroller.behaviors.addItem(new TouchScrollBehavior(photo));
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<rx:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:rx="http://rx.reflex.io/2010"
xmlns:behaviors="reflex.behaviors.*" >
<rx:Scroller width="400" height="400">
<rx:behaviors>
<behaviors:TouchScrollBehavior />
</rx:behaviors>
<rx:BitmapImage source="http://farm3.static.flickr.com/2766/4474105201_af63f79a2d_b.jpg" />
</rx:Scroller>
</rx:Application>
@davidortinau
Copy link
Author

The mxml version runs, the AS version doesn't. I'm just curious what the appropriate AS expression of the mxml should be.

@benstucki
Copy link

A few things... The first is that when you use the standard Flash APIs addChild/removeChild it acts exactly like it does in Flash, and so Reflex doesn't touch it. It doesn't position it or add interactivity or anything like that. That API is preserved for you to take manual control. The Reflex version is to use the content property (ie. component.content.addItem(something)). This tells reflex to automatically do layout and positioning, add behaviors and whatever other "automatic" stuff we provide. This is consistent throughout all the components that can contain items. Also, when you add a behavior to the behaviors collection, it is automatically assigned the target (in this case the scroller). No other target should be assigned.

http://gist.github.com/642543

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment