• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

How to retrieve current view object programatically and pass it to Native code?

Community Beginner ,
May 04, 2015 May 04, 2015

Copy link to clipboard

Copied

Hello,

I work for InMobi and am in the process of updating our existing ANE to support Native Ad Formats. For that I need to pass View/View Group object (like we have View/ViewGroup classes in Android that gives you the current view/activity object) to native code.

How can i get the current view object programmatically and pass it to Native (Android/iOS) code?

Content of HomeView.mxml :

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

        xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">

    <fx:Declarations>

        <!-- Place non-visual elements (e.g., services, value objects) here -->

    </fx:Declarations>

<s:Button x="0" y="60" label="Create Banner1" click="createBanner1(event)"/>

    <s:Button x="0" y="110" label="Create Banner2" click="createBanner2(event)"/>

    <s:Button x="0" y="160" label="Load Banner1" click="loadBanner1(event)"/>

    <s:Button x="0" y="210" label="Load Banner2" click="loadBanner2(event)"/>

    <s:Button x="0" y="260" label="Remove Banner1" click="removeBanner1(event)"/>

    <s:Button x="0" y="310" label="Remove Banner2" click="removeBanner2(event)"/>

    <s:Button x="0" y="360" label="Load Interstitial1" click="loadInterstitial1(event)"/>

    <s:Button x="0" y="410" label="Load Interstitial2" click="loadInterstitial2(event)"/>

   

</s:View>

I am using Flash Builder 4.7.

Can some one provide their expert advice on this?

Views

825

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 05, 2015 May 05, 2015

Copy link to clipboard

Copied

We recently developed a native extension for iOS that uses native views and storyboards.

I doubt it's possible from AS3 to grab the current UIView, but it is possible from native code.

We used the following objective-C code in our ANE that works well.

In this case, controller is your custom ViewController, and this code adds its view to the main view (AIR apps are single-view apps):

[[[[UIApplication sharedApplication] keyWindow] rootViewController] addChildViewController:controller];

[[[[UIApplication sharedApplication] keyWindow] rootViewController].view addSubview:controller.view];

[controller didMoveToParentViewController:[[[UIApplication sharedApplication] keyWindow] rootViewController]];

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 17, 2015 Jun 17, 2015

Copy link to clipboard

Copied

Thanks for your reply.

Can you please advice how to do the same in case of Android? I tried getting the current active view in actionscript by calling "navigator.activeview" but I don't know how to pass it to native code.

Can you please help?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 17, 2015 Jun 17, 2015

Copy link to clipboard

Copied

I haven't written an ANE yet for Android so I can't help you much, but I believe you'd have to do it from native code as well, following the Android APIs.  The native view won't be accessible from AS3 because it's not an AS3 object, it's a native (probably Java) object.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 17, 2015 Jun 17, 2015

Copy link to clipboard

Copied

Ok, how about accessing the AS3 created view in native code (Android/iOS)? Because my UI is made using AS3 and I want to access the view on my native code. Possible?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 18, 2015 Jun 18, 2015

Copy link to clipboard

Copied

LATEST

No idea.  All I know is how to get the root view controller to add additional native storyboards to the stack (over the AIR content).  You could put Obj-C code in maybe to iterate through views off the root and see if you can find it?? 

The inner native workings of AIR apps are a mystery. We wanted to modify the default storyboards to support UINavigationController-based transitions on our native screens, but they're precompiled and buried in the AIR SDK....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines