Embed StageText within a movieclip? - ios

Is it possible to embed StageText within a MovieClip?
I've added about 20 instances of StageText to a page (each page is a MovieClip), and I was hoping to have all these text fields move, fade, etc. along with the MovieClip.
Right now when I fade the MovieClip out, the StageText remains and I have to remove them individually by script.
Here's an example of the code I'm using to add the StageText
var textField1:StageText = new StageText();
textField1.softKeyboardType = SoftKeyboardType.PUNCTUATION;
textField1.returnKeyLabel = ReturnKeyLabel.GO;
textField1.stage = this.stage;
textField1.viewPort = new Rectangle(800, 200, 100, 30);
textField1.text = String(0);
I'm thinking it would have something to do with the stage = this.stage; line or perhaps the viewPort, but there isn't much information on Google about StageText so I can't find anything on that.

No. I think they are just overlayed overtop of your flash content:
http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/text/StageText.html
"When native inputs are used, StageText objects are not display objects and you cannot add them to the Flash display list. "

Related

Scroll bar in LibreOffice dialog

I am trying to make an image picker component in LibreOffice.
I have a dialog that is dynamically filled with images. When the user clicks on one images, it should be selected and the dialog should be closed.
The problem is that the number of images is variable. So I need to enable scrolling in the dialog (so that the user can navigate through all images).
There seems to be some properties on the dialog object (Scrollbars, Scroll width, Scroll height, etc)
However, I cannot find a way to use them anywhere.
Any ideas?
The scrollbar is one of the Controls available through the dialog box editor. That is the easier way to put a ScrollBar on a dialog box. Just insert it like any other control. There is a harder way via DialogModel.addControl but that seems non-essential to answering this question.
If you add a scrollbar to the dialog box and run the dialog box, you will find it does nothing by default. The functionality (apparently) must be written into a macro. The appropriate triggering event is the While Adjusting event on the ScrollBar object, although it does not trigger the macro simply with the "Test Mode" function in the dialog editor. Running the dialog box through a macro triggers the While Adjusting event when the scroll arrows are triggered, when the slider area is clicked to move the slider, and when the slider itself is dragged. The Object variable returned by the scrollbar event contains a property .Value which is an absolute value between 0 and the EventObject.Model.ScrollValueMax, which allows you to manipulate the other objects on the page manually based on the position of the slider.
Yes, that's right, manipulate objects manually. The sole example I found, from the LibreOffice 4.5 SDK, does precisely this. Of course, it is not as bad as it sounds, because one can iterate through all of the objects on the page by reading the array Dialog.getControls(). In any event, the secret sauce of the example provided in the SDK is to define Static variables to save the initial positions of all of the objects you manipulate with the scrollbar and then simply index those initial positions based on a ratio derived from the scrollbar Value divided by the ScrollValueMax.
Here is a very simple working example of how to scroll. This requires a saved Dialog1 in the Standard library of your document, which contains an object ScrollBar1 (a vertical scrollbar) and Label1 anywhere in the dialog. The ScrollBar1 must be configured to execute the macro ScrBar subroutine (below) on the While Adjusting event. Open the dialog by executing the OpenDialog macro and the scrollbar will move the Label1 control up and down in proportion to the page.
Sub OpenDialog
DialogLibraries.LoadLibrary("Standard")
oVariable = DialogLibraries.Standard.Dialog1
oDialog1 = CreateUnoDialog( oVariable )
oDialog1.Execute()
End Sub
Sub ScrBar (oEventObj As Object)
Static bInit As Boolean
Static PositionLbl1Y0 As Long
oSrc = oEventObj.Source
oSrcModel = oSrc.Model
scrollRatio = oEventObj.Value / oSrcModel.ScrollValueMax
oContx = oSrc.Context
oContxModl = oContx.Model
oLbl1 = oContx.getControl("Label1")
oLbl1Model = oLbl1.Model
REM on initialization remember the position of the label
If bInit = False Then
bInit = True
PositionLbl1Y0 = oLbl1Model.PositionY
End If
oLbl1Model.PositionY = PositionLbl1Y0 - (scrollRatio * oContx.Size.Height)
End Sub
The example provided by the SDK does not run on my setup, but the principles are sound.
There appears to be a second improvised method closer to the functionality one might expect. This method uses the DialogModel.scrollTop property. The property appears to iterate the entire box up or down as a scroll based on the user input. There are two problems using this methodology, however. First, unless you put the scrollbar somewhere else, the scroll bar will scroll away along with the rest of the page. You will need to adjust the location of the scrollbar precisely to compensate for/negate the scrolling of the entire page. In the example below I tried but did not perfect this. Second, the property seems to miss inputs with frequency and easily goes out of alignment/ enters a maladjusted state. Perhaps you can overcome these limitations. Here is the example, relying on the same setup described above.
Sub ScrBar (oEventObj As Object)
Static scrollPos
oSrc = oEventObj.Source
oSrcModel = oSrc.Model
scrollRatio = oEventObj.Value / oSrcModel.ScrollValueMax
If IsEmpty(scrollPos) = False Then
scrollDiff = oEventObj.Value - scrollPos
Else
scrollDiff = oEventObj.Value
End If
scrollPos = oEventObj.Value
oContx = oSrc.Context
oContxModl = oContx.Model
oContxModl.scrollTop = scrollDiff * -1
oSrcModel.PositionY=(scrollRatio * oContx.Size.Height/5) * -1
End Sub
This (sort of) will scroll the contents of the entire dialog box, within limits and with the caveats noted above.

How can I set up a DialogBox in Swift?

I would like to have a box appear in the screen (some kind of textfield) and want to make it look like the static character is talking to the user (like the link below). The text needs to be slowly shown to the user (not all at once). I'm not sure the best way to implement this. Also, I'm not sure how to wrap the text within the box.
http://lightsendgame.com/images/screenshots/CrystalsRoom.JPG
You can create a UIView with a UILabel inside and set the alpha to 0. Whenever you want the box to appear (on button press for example) you can execute a UIAnimation block to set the alpha to 1. This will give the fade in effect you want.
How you display the text is up to you, use the styling in xCode for this, most of us aren’t the best of designers ;)
About the text which slowly comes in to view, you can iterate through a string and keep on adding the next letting in the string to another string. After you’ve added one letter to the second string, output this second string to the user. This will go pretty quick though, if you want to slow this down you can make the thread sleep for an x amount between the iterations.
import UIKit
import XCPlayground
var text:String = “Slowly old-school displaying text is awesome!"
var scrollingText:String = “"
var label:UILabel = UILabel(frame: CGRectMake(0, 0, 400, 100))
for char in text{
scrollingText = "\(scrollingText)\(char)"
label.text = scrollingText
}

Is is possible to divide page control dots into two lines?

I got a number of dots of page control, obviously it's too long and beyond the screen width.
Set pagecontrol=[[UIPageControl alloc] initWithFrame:CGRectMake(108, 500, 100, 50)]; to contraint its width, but looks not work.
Is it possible to divid these dots into two lines or even more?
Taking a look at the Tasks UIPageControl offers, there's no easy way to implement multi-line page control. Also, the sizeForNumberOfPages: method, there's no break mode or anything to allow you to control the number of dots per line, it will most likely just return X * dotSize, where X is the number of pages.
Also, the note On iPhone and iPod touch, about 20 page control dots fit on the screen before they are clipped says that there's no built in method to create multi-line page control.
You can of course always create a custom class, but I REALLY wouldn't suggest doing that. The user won't expect (or like) a multi-line page control anyway.
You can use something like 10 of 50 like the iBooks app uses.

Can I programmatically add link annotation to PDFs?

I am making an iPad app that uses UIWebView to display PDFs. I have a PDF that I would like to programmatically add links to. For simplicity, lets say there are 10 paragraphs. They are all numbered and have a few lines of text in them. I want to be able to somehow add a basic link to the PDF so that if paragraph 2 is touched, then my UIWebView can process the request that is associated with paragraph 2.
I have no idea what the structure of the PDF is like on the inside. I have no clue how to scale this to each paragraph of several hundred pages. But I am wondering if I can somehow add a link or HTML to the PDF so that I can manipulate it with my app.
Thanks!
To be clear, I am viewing this PDF on an iOS device but I recognize that the solution to my question might not have anything to do with Cocoa-touch frameworks. I am looking for any sort of solution that will allow me to add invisible links to certain areas of my PDF.
If you want an iPad app to recognize text fields, buttons, links from a pdf. You can edit the actual pdf (you'll need a version of Adobe Acrobat) and add those fields to the pdf. In your ios code parse the pdf fields using something like:
in a parse method:
-(void)parse:(CGPDFPageRef)page
{
for (int i = 0; i < CGPDFArrayGetCount (annotations); i++)
CGPDFArrayGetCount returns the number of items in a PDF array.
in the loop grab the field name:
if (CGPDFDictionaryGetString(dict, "T", &stringRef))
{
char *s = (char *) CGPDFStringGetBytePtr(stringRef);
fieldName = [NSString stringWithCString:s encoding:NSUTF8StringEncoding];
}
check to see what you want to do if a field name matches, say "button_1" or "hlink_3":
if ([fieldName isEqualToString:#"hlink_3"])
{
// do whatever, example add a button where the field was
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = rect;
[self addSubview:button];
}
There's a lot more to it, but this is the general idea.

Spotify API Drag & Drop playlists

I want to create a drag and droppable playlist using the Spotify API.
var tracks = models.library.tracks;
var playlist = new models.Playlist();
// loop through all tracks and add them to the playlist
for (var i = 0; i < 25; i++) {
var track = models.Track.fromURI(tracks[i].data.uri);
playlist.add(track);
}
// add playlist to view
var playlistView = new views.List(playlist);
$('#playlist').html(playlistView.node);
How would I make this playlist enabled for dragging and dropping the tracks?
Is this already built in to the Spotify API (but not documented yet)?
I tried to implement it myself using jQuery UIs sortable function.
$('#playlist').sortable();
However, Spotify playlists aren't simple ul and li child elements, so this didn't work out.
The issue isn't that the playlist isn't displayed using ul and li elements. The jQuery UI sortable function actually works fine with a div tag containing a tags, particularly if (as is the case with Spotify) the a tags have their display style set to table. You simply need to tell the function what child items are sortable by using something like:
$('#playlist').sortable({ items: 'a.sp-item' });
That tells it that links with the class of sp-item are sortable.
However, it still doesn't quite work when doing that as the items snap back to the original positions. This is because each row in the playlist is set to use absolute positioning and uses the -webkit-transform CSS property to position it at the correct Y-coordinates. This results in the "snap-back" experienced.
I have found a workaround for this, although it is rather a hack. Simply add the following code before you set the list to sortable:
setTimeout(function() {
$('#playlist > div > div a.sp-item').attr("style","").css("position","relative");
}, 100);
This basically removes the "-webkit-transform" style from all the links in the playlist and changes them to use relative positioning (the timeout is because the list doesn't appear to be fully constructed immediately after creating it). Strangely this doesn't seem to affect the display of the playlist at all, so it makes me wonder why it was done like this...
I did this exact thing a few days ago, for the site below. Scroll down, click the tabs, add a few tracks to build up a list and drag and drop about.
http://cultureclash.redbull.co.uk/getonstage/
The pertinent code is at http://cultureclash.redbull.co.uk/getonstage/js/getonstage-ui.js starting at line 106. The playlist itself is stored somewhere else as an array of tracks encoded just as Spotify has them.
When the user adds a track, I grab that array and put it through a template to generate the DOM for the sortable, then I give data-index attributes to each li to keep track of which index of the original array they represent. When the sortstop event fires, I go through the ul, take note of the new order, and shift the array to match.
Have a deeper look at that file and play about with the app using a DOM inspector to work out the finer details.

Resources